Contest Duration: ~ (local time) (150 minutes) Back to Home

Submission #2289522

Source Code Expand

Copy
```#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1e9+7;
const ll  longinf = 1LL<<60;
const int mod=1e9+7;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

ll dp[300001][3][3];
ll all[300001];
int m,s[300003];
string t;

ll rec(int n,int a,int b){
if(dp[n][a][b]!=-1)return dp[n][a][b];
ll ret=0;
if(a!=0&&b!=0)ret+=all[n+2];
if(a!=0&&b!=1){
if(n==m-3)ret+=rec(n+2,s[n+2],0);
else {
if(s[n+2]!=0)ret+=rec(n+2,1,s[n+3]);
if(s[n+2]!=1)ret+=rec(n+2,1,0)*max(s[n+3],1);
}
}
if(a!=1&&b!=0)
ret=(ret+rec(n+2,s[n+2],s[n+3]))%mod;
if(a!=1&&b!=1)
ret=(ret+rec(n+2,0,s[n+3])*max(s[n+2],1))%mod;
return dp[n][a][b]=ret%mod;
}

int main(){
cin>>t;
m=t.size();
rep(i,m){
if(t[i]=='0')s[i]=0;
if(t[i]=='1')s[i]=1;
if(t[i]=='?')s[i]=2;
}
s[m]=0;
rep(i,m+1)rep(j,3)rep(k,3){
dp[i][j][k]=-1;
}
dp[m-1][0][0]=0;
dp[m-1][2][0]=1;
dp[m-1][1][0]=1;

all[m]=1;
rep(i,m){
if(s[m-i-1]==2)all[m-i-1]=2*all[m-i]%mod;
else all[m-i-1]=all[m-i];
}
cout<<rec(0,s[0],s[1])<<endl;
return 0;
}```

#### Submission Info

Submission Time 2018-04-01 02:48:09+0900 E - Median Replace tempura0224 C++14 (GCC 5.4.1) 1600 1412 Byte AC 39 ms 36996 KB

#### Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 1600 / 1600 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 1 ms 2304 KB
02.txt 2 ms 2304 KB
03.txt 2 ms 2304 KB
04.txt 2 ms 2304 KB
05.txt 2 ms 2304 KB
06.txt 12 ms 13312 KB
07.txt 39 ms 36996 KB
08.txt 7 ms 8320 KB
09.txt 29 ms 31108 KB
10.txt 19 ms 22404 KB
11.txt 28 ms 31108 KB
12.txt 17 ms 22660 KB
13.txt 32 ms 36996 KB
14.txt 2 ms 2432 KB
15.txt 29 ms 36996 KB
16.txt 14 ms 16900 KB
17.txt 28 ms 31108 KB
18.txt 16 ms 19588 KB
19.txt 27 ms 31108 KB
20.txt 5 ms 6016 KB
21.txt 35 ms 36996 KB
22.txt 23 ms 26628 KB
23.txt 33 ms 36996 KB
24.txt 8 ms 11520 KB
25.txt 30 ms 34052 KB
26.txt 11 ms 13440 KB
27.txt 31 ms 36996 KB
28.txt 10 ms 13312 KB
29.txt 37 ms 36996 KB
30.txt 27 ms 32900 KB
31.txt 35 ms 36996 KB
32.txt 19 ms 22788 KB
33.txt 34 ms 36996 KB
34.txt 16 ms 22660 KB
35.txt 29 ms 36996 KB
36.txt 24 ms 25732 KB
37.txt 38 ms 36996 KB
38.txt 22 ms 23556 KB
39.txt 38 ms 36996 KB
40.txt 7 ms 8832 KB
41.txt 38 ms 36996 KB
42.txt 9 ms 13056 KB
43.txt 27 ms 36996 KB
s1.txt 2 ms 2304 KB
s2.txt 2 ms 2304 KB
s3.txt 2 ms 2304 KB