CSES - Leirikisa 5 - Results
Submission details
Task:jedan
Sender:Hansuzu
Submission time:2016-08-02 16:47:14 +0300
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#1ACCEPTED0.11 sdetails
#2ACCEPTED0.11 sdetails
#3ACCEPTED0.10 sdetails
#4ACCEPTED0.12 sdetails
#5ACCEPTED0.11 sdetails
#6ACCEPTED0.12 sdetails
#7ACCEPTED0.13 sdetails
#80.11 sdetails
#90.12 sdetails
#100.12 sdetails
#110.11 sdetails
#120.12 sdetails
#130.11 sdetails
#14ACCEPTED0.11 sdetails
#15ACCEPTED0.11 sdetails
#160.10 sdetails
#170.12 sdetails
#180.11 sdetails
#190.12 sdetails
#20ACCEPTED0.11 sdetails
#21ACCEPTED0.11 sdetails
#22ACCEPTED0.12 sdetails
#23ACCEPTED0.12 sdetails
#24ACCEPTED0.12 sdetails
#25ACCEPTED0.12 sdetails
#26ACCEPTED0.11 sdetails
#270.11 sdetails
#280.13 sdetails
#290.14 sdetails
#300.14 sdetails
#310.12 sdetails
#320.14 sdetails
#330.11 sdetails
#340.11 sdetails
#350.13 sdetails
#360.13 sdetails
#370.14 sdetails
#380.11 sdetails

Code

#include <iostream>
using namespace std;
int N;
const int M=1000000007;


int h[101010];

int cm[5111][5111];

long long calc(int dh, int dp, int h0){
  if (dh<0) dh=-dh;
  if (dh>dp) return 0;
  if (dh>5000) return 0;
  if (dp>5000){
    int a=dp/2;
    int b=dp-a;
    long long s=0;
    for (int h=0; h<h0+a+1; ++h){
      s+=calc(h-h0, a, min(h, h0))*calc(h0+dh-h, b, min(h0+dh, h));
    }
    return s;
  }
  long long s=0;
  for (int i=0; i<=h0; ++i){
    s+=cm[dp][dh];
    s%=M;
    --dp; ++dh;
    if (dh>dp) break;
  }
  return s;
}

int main(){
  cm[0][0]=1;
  for (int dp=1; dp<5111; ++dp){
    for (int dh=min(dp, 51110); dh>=0; --dh){
      cm[dp][dh]=cm[dp-1][dh+1]+cm[dp-1][dh];
      cm[dp][dh]%=M;
      if (dh>0)cm[dp][dh]+=cm[dp-1][dh-1];
      cm[dp][dh]%=M;
    }
  }
  cin >> N;
  for (int i=0; i<N; ++i){
    cin >> h[i];
    if (i==0 || i==N-1){
      if (h[i]!=-1 && h[i]!=0){
	cout << 0 << "\n";
	return 0;
      }
      h[i]=0;
    }
  }
  long long ans=1;
  int li=0;
  int lh=0;
  for (int i=1; i<N; ++i){
    if (h[i]==-1) continue;
    ans*=calc(lh-h[i], i-li, min(h[i], lh));
    ans%=M;
    if (ans==0) break;
    lh=h[i];
    li=i;
  }
  cout << ans << "\n";
}

Test details

Test 1

Verdict: ACCEPTED

input
3
-1 2 -1

correct output
0

user output
0

Test 2

Verdict: ACCEPTED

input
3
-1 -1 -1

correct output
2

user output
2

Test 3

Verdict: ACCEPTED

input
6
-1 -1 -1 2 -1 -1

correct output
3

user output
3

Test 4

Verdict: ACCEPTED

input
1
-1

correct output
1

user output
1

Test 5

Verdict: ACCEPTED

input
1
0

correct output
1

user output
1

Test 6

Verdict: ACCEPTED

input
1
1

correct output
0

user output
0

Test 7

Verdict: ACCEPTED

input
15
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

correct output
113634

user output
113634

Test 8

Verdict:

input
30
-1 -1 -1 -1 -1 -1 -1 -1 7 -1 -...

correct output
33792

user output
33696

Test 9

Verdict:

input
40
-1 -1 -1 -1 -1 -1 -1 6 -1 -1 -...

correct output
44058168

user output
31783752

Test 10

Verdict:

input
50
-1 -1 -1 -1 4 -1 -1 -1 -1 -1 -...

correct output
885261321

user output
627501000

Test 11

Verdict:

input
100
-1 -1 -1 -1 -1 -1 -1 -1 7 -1 -...

correct output
630105363

user output
708326824

Test 12

Verdict:

input
200
0 -1 -1 -1 4 -1 -1 -1 -1 0 -1 ...

correct output
584749136

user output
881863820

Test 13

Verdict:

input
300
-1 -1 0 -1 -1 -1 -1 -1 -1 -1 -...

correct output
440962689

user output
76427820

Test 14

Verdict: ACCEPTED

input
500
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

correct output
861085225

user output
861085225

Test 15

Verdict: ACCEPTED

input
499
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

correct output
686858355

user output
686858355

Test 16

Verdict:

input
500
0 0 -1 -1 -1 3 -1 -1 -1 6 6 -1...

correct output
287620623

user output
719127853

Test 17

Verdict:

input
500
0 -1 -1 1 -1 0 -1 0 -1 -1 3 -1...

correct output
132437565

user output
640887167

Test 18

Verdict:

input
500
0 -1 1 -1 2 2 -1 4 -1 -1 -1 1 ...

correct output
545015067

user output
930075931

Test 19

Verdict:

input
500
-1 1 1 -1 1 -1 1 -1 -1 1 -1 -1...

correct output
394701022

user output
605436920

Test 20

Verdict: ACCEPTED

input
500
0 -1 -1 2 -1 -1 -1 -1 -1 -1 -1...

correct output
287409105

user output
287409105

Test 21

Verdict: ACCEPTED

input
500
0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -...

correct output
455719894

user output
455719894

Test 22

Verdict: ACCEPTED

input
500
-1 1 -1 -1 -1 -1 -1 -1 -1 -1 -...

correct output
174226870

user output
174226870

Test 23

Verdict: ACCEPTED

input
500
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

correct output
861085225

user output
861085225

Test 24

Verdict: ACCEPTED

input
1000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

correct output
812718674

user output
812718674

Test 25

Verdict: ACCEPTED

input
2000
-1 1 -1 -1 -1 -1 -1 -1 -1 -1 -...

correct output
93994771

user output
93994771

Test 26

Verdict: ACCEPTED

input
3000
-1 0 -1 -1 -1 -1 -1 -1 -1 -1 -...

correct output
335231082

user output
335231082

Test 27

Verdict:

input
5000
0 -1 2 -1 1 2 -1 -1 5 -1 -1 7 ...

correct output
799295101

user output
892766840

Test 28

Verdict:

input
7000
0 -1 0 0 -1 0 -1 1 0 1 0 0 -1 ...

correct output
436287141

user output
-258737161

Test 29

Verdict:

input
8000
0 -1 1 -1 3 -1 1 -1 1 0 -1 -1 ...

correct output
88524447

user output
585896457

Test 30

Verdict:

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

correct output
129950957

user output
256901097

Test 31

Verdict:

input
10000
-1 0 -1 -1 3 2 -1 -1 -1 -1 1 -...

correct output
598246902

user output
28724343

Test 32

Verdict:

input
10000
-1 1 0 -1 2 1 -1 1 -1 0 -1 -1 ...

correct output
105842640

user output
-134219256

Test 33

Verdict:

input
10000
0 -1 0 -1 -1 -1 4 3 -1 -1 -1 -...

correct output
133310608

user output
195344365

Test 34

Verdict:

input
10000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

correct output
484205143

user output
250658906

Test 35

Verdict:

input
10000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

correct output
904817827

user output
497597117

Test 36

Verdict:

input
10000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

correct output
966971895

user output
494433599

Test 37

Verdict:

input
10000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

correct output
664825423

user output
703520798

Test 38

Verdict:

input
10000
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

correct output
681928184

user output
664879921