CSES - APIO 2007 - Results
Submission details
Task:Mobiles
Sender:jarvenp
Submission time:2019-03-07 15:08:19 +0200
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#1ACCEPTED0.02 sdetails
#2ACCEPTED0.01 sdetails
#3ACCEPTED0.02 sdetails
#4ACCEPTED0.02 sdetails
#5ACCEPTED0.01 sdetails
#6ACCEPTED0.02 sdetails
#7ACCEPTED0.03 sdetails
#8ACCEPTED0.03 sdetails
#90.01 sdetails
#100.02 sdetails
#110.02 sdetails
#120.01 sdetails
#13ACCEPTED0.02 sdetails
#14ACCEPTED0.02 sdetails
#15ACCEPTED0.02 sdetails
#16ACCEPTED0.02 sdetails
#17ACCEPTED0.01 sdetails
#18ACCEPTED0.02 sdetails
#19ACCEPTED0.01 sdetails
#20ACCEPTED0.02 sdetails
#21ACCEPTED0.03 sdetails
#220.01 sdetails
#230.03 sdetails
#240.02 sdetails
#250.02 sdetails
#26ACCEPTED0.02 sdetails
#27ACCEPTED0.02 sdetails
#28ACCEPTED0.02 sdetails
#290.02 sdetails
#30ACCEPTED0.03 sdetails
#31ACCEPTED0.03 sdetails
#32ACCEPTED0.05 sdetails
#330.07 sdetails
#340.07 sdetails
#350.08 sdetails
#360.07 sdetails
#370.06 sdetails
#380.07 sdetails
#390.07 sdetails
#400.07 sdetails
#410.07 sdetails
#420.07 sdetails

Code

#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second

int64_t n;
int64_t m[200000];
int64_t p[100001];
pair<int64_t,int64_t> ans[200000];
int64_t toy=0;

void q(int64_t index){
  if(m[index] == -1){
    ans[index] = {0,0};
    return;
  }
  if(m[index] == -2){
    ans[index] = {0,1};
    return;
  }
  pair<int64_t,int64_t> t1,t2;
  q(index*2);
  q(index*2+1);
  t1 = ans[index*2];
  t2 = ans[index*2+1];
  if((t1.F == -1) || (t2.F == -1)){
    ans[index] = {-1,0};
  }
  else if((t1.S == 2) && (t2.S == 2)){
    ans[index] = {0,-1};
  }
  else if((t1.S == 0) && (t2.S == 2)){
    ans[index] = {t1.F+t2.F+1,2};
  }
  else if((t1.S == 2) && (t2.S == 0)){
    ans[index] = {t1.F+t2.F,2};
  }
  else if((t1.S == 2) && (t2.S == 1)){
    ans[index] = {t1.F+t2.F+1,2};
  }
  else if((t1.S == 1) && (t2.S == 2)){
    ans[index] = {t1.F+t2.F,2};
  }
  else if((t1.S == 0) && (t2.S == 0)){
    ans[index] = {t1.F+t2.F,0};
  }
  else if((t1.S == 1) && (t2.S == 1)){
    ans[index] = {t1.F+t2.F,1};
  }
  else if((t1.S == 0) && (t2.S == 1)){
    ans[index] = {t1.F+t2.F+1,2};
  }
  else if((t1.S == 1) && (t2.S == 0)){
    ans[index] = {t1.F+t2.F,2};
  }
  return;
}

int main(){
  cin >> n;
  p[1] = 1;
  for(int64_t i=0; i<200000; i++){
    m[i] = 0;
  }
  for(int64_t i=0; i<n; i++){
    int64_t l,r;
    cin >> l >> r;
    if(l != -1){
      p[l] = p[i+1]*2;
    }
    else{
      toy++;
      m[p[i+1]*2] = -1;
    }
    if(r != -1){
      p[r] = p[i+1]*2+1;
    }
    else{
      toy++;
      m[p[i+1]*2+1] = -1;
    }
  }
  int64_t f = 0;
  int64_t a=0;
  for(int64_t i=0; (1<<i) < 100000; i++){
    for(int64_t i2=0; i2<(1<<i); i2++){
      if(m[(1<<i)+i2] == -1){
	if(f == 0){
	  f = 1;
	}
	else if(f == 2){
	  m[(1<<i)+i2] = -2;
	}
	a++;
      }
    }
    if(f != 0){
      f++;
    }
    if(f == 3){
      if(a != toy){
	cout << "-1\n";
	return 0;
      }
      break;
    }
  }
   q(1);
  cout << ans[1].F << "\n";
}

Test details

Test 1

Verdict: ACCEPTED

input
1
-1 -1

correct output
0

user output
0

Test 2

Verdict: ACCEPTED

input
2
2 -1
-1 -1

correct output
0

user output
0

Test 3

Verdict: ACCEPTED

input
2
-1 2
-1 -1

correct output
1

user output
1

Test 4

Verdict: ACCEPTED

input
4
2 3
4 -1
-1 -1
-1 -1

correct output
0

user output
0

Test 5

Verdict: ACCEPTED

input
4
2 3
-1 4
-1 -1
-1 -1

correct output
1

user output
1

Test 6

Verdict: ACCEPTED

input
4
2 3
-1 -1
4 -1
-1 -1

correct output
1

user output
1

Test 7

Verdict: ACCEPTED

input
4
2 3
-1 -1
-1 4
-1 -1

correct output
2

user output
2

Test 8

Verdict: ACCEPTED

input
5
2 3
4 5
-1 -1
-1 -1
...

correct output
0

user output
0

Test 9

Verdict:

input
5
2 3
4 -1
5 -1
-1 -1
...

correct output
-1

user output
0

Test 10

Verdict:

input
5
2 3
4 -1
-1 5
-1 -1
...

correct output
-1

user output
0

Test 11

Verdict:

input
5
2 3
-1 4
5 -1
-1 -1
...

correct output
-1

user output
0

Test 12

Verdict:

input
5
2 3
-1 4
-1 5
-1 -1
...

correct output
-1

user output
0

Test 13

Verdict: ACCEPTED

input
5
2 3
-1 -1
4 5
-1 -1
...

correct output
1

user output
1

Test 14

Verdict: ACCEPTED

input
6
2 3
4 5
6 -1
-1 -1
...

correct output
0

user output
0

Test 15

Verdict: ACCEPTED

input
6
2 3
4 5
-1 6
-1 -1
...

correct output
1

user output
1

Test 16

Verdict: ACCEPTED

input
6
2 3
4 -1
5 6
-1 -1
...

correct output
1

user output
1

Test 17

Verdict: ACCEPTED

input
6
2 3
-1 4
5 6
-1 -1
...

correct output
2

user output
2

Test 18

Verdict: ACCEPTED

input
19
2 3
6 5
4 7
-1 -1
...

correct output
-1

user output
-1

Test 19

Verdict: ACCEPTED

input
9
3 2
4 5
-1 -1
6 9
...

correct output
-1

user output
-1

Test 20

Verdict: ACCEPTED

input
4
-1 2
3 4
-1 -1
-1 -1

correct output
-1

user output
-1

Test 21

Verdict: ACCEPTED

input
12
3 2
4 5
-1 6
7 9
...

correct output
-1

user output
-1

Test 22

Verdict:

input
10
3 2
7 5
4 6
8 10
...

correct output
-1

user output
0

Test 23

Verdict:

input
1000
2 -1
-1 3
4 -1
5 -1
...

correct output
-1

user output
(empty)

Test 24

Verdict:

input
10000
2 -1
-1 3
4 -1
5 -1
...

correct output
-1

user output
(empty)

Test 25

Verdict:

input
100000
2 -1
-1 3
4 -1
5 -1
...

correct output
-1

user output
(empty)

Test 26

Verdict: ACCEPTED

input
10
2 3
6 5
7 4
-1 -1
...

correct output
2

user output
2

Test 27

Verdict: ACCEPTED

input
18
2 3
7 6
5 4
11 9
...

correct output
3

user output
3

Test 28

Verdict: ACCEPTED

input
13
3 2
4 5
7 6
-1 -1
...

correct output
-1

user output
-1

Test 29

Verdict:

input
660
3 2
5 6
7 4
10 8
...

correct output
-1

user output
0

Test 30

Verdict: ACCEPTED

input
1250
2 3
6 7
5 4
10 14
...

correct output
7

user output
7

Test 31

Verdict: ACCEPTED

input
5000
2 3
6 7
5 4
11 14
...

correct output
4

user output
4

Test 32

Verdict: ACCEPTED

input
32767
2 3
5 4
7 6
13 14
...

correct output
0

user output
0

Test 33

Verdict:

input
100000
2 3
5 7
4 6
15 14
...

correct output
7

user output
(empty)

Test 34

Verdict:

input
98348
3 2
7 5
6 4
10 8
...

correct output
-1

user output
(empty)

Test 35

Verdict:

input
100000
2 3
5 7
4 6
15 14
...

correct output
7

user output
(empty)

Test 36

Verdict:

input
99999
3 2
7 5
6 4
10 8
...

correct output
5

user output
(empty)

Test 37

Verdict:

input
98348
3 2
7 5
6 4
10 8
...

correct output
-1

user output
(empty)

Test 38

Verdict:

input
98303
3 2
5 4
7 6
9 8
...

correct output
1

user output
(empty)

Test 39

Verdict:

input
98304
3 2
5 4
7 6
9 8
...

correct output
16

user output
(empty)

Test 40

Verdict:

input
99989
3 2
5 4
7 6
9 8
...

correct output
15

user output
(empty)

Test 41

Verdict:

input
99989
2 3
4 5
6 7
8 9
...

correct output
15

user output
(empty)

Test 42

Verdict:

input
100000
3 2
5 4
7 6
9 8
...

correct output
16

user output
(empty)