Submission #838560
Source Code Expand
Copy
#include<bits/stdc++.h> using namespace std; const int maxn = 5000+100; typedef long long LL; const LL mod = 1e9+7; LL dp[2][maxn][maxn]; char s[maxn]; int n; int main() { //freopen("./test.txt","r",stdin); scanf("%d",&n); scanf("%s",s+1); int m = strlen(s+1); memset(dp,0,sizeof(dp)); int p = 0; dp[0][0][0] = 1; for(int i = 0;i < n;++i) { memset(dp[p^1],0,sizeof(dp[p^1])); for(int j = 0;j <= m;++j) for(int nl = j;nl <= i;++nl) { if(dp[p][j][nl] == 0) continue; // if(i == 1) // printf("**** %d %d %d\n",j,nl,dp[p][j][nl]); if(j == m) { dp[p^1][j][nl+1] = (dp[p^1][j][nl+1] + 2*dp[p][j][nl])%mod; if(nl > j) dp[p^1][j][nl-1] = (dp[p^1][j][nl-1] + dp[p][j][nl])%mod; else dp[p^1][j-1][nl-1] = (dp[p^1][j-1][nl-1] + dp[p][j][nl])%mod; } else { if(j == nl) { dp[p^1][j+1][nl+1] = (dp[p^1][j+1][nl+1] + dp[p][j][nl])%mod; dp[p^1][j][nl+1] = (dp[p^1][j][nl+1] + dp[p][j][nl])%mod; // if(i == 0 && j == 0 && nl == 0) // printf("*** %d\n",dp[p^1][nxtj][nxtl]); int nxtl = max(nl-1,0); int nxtj = nxtl; dp[p^1][nxtj][nxtl] = (dp[p^1][nxtj][nxtl] + dp[p][j][nl])%mod; } else { dp[p^1][j][nl+1] = (dp[p^1][j][nl+1] + 2*dp[p][j][nl])%mod; dp[p^1][j][nl-1] = (dp[p^1][j][nl-1] + dp[p][j][nl])%mod; } } } p ^= 1; // if(i == 1) // printf("*** %d\n",dp[p][0][0]); } LL res = dp[p][m][m]; printf("%lld\n",res); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Unhappy Hacking |
User | wumpus |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2116 Byte |
Status | MLE |
Exec Time | 2143 ms |
Memory | 406656 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:16:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n); ^ ./Main.cpp:17:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s",s+1); ^
Judge Result
Set Name | Sample | Sub1 | Sub2 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 400 | 0 / 400 | ||||||||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | 0_01, 0_02, 0_03 |
Sub1 | 0_01, 0_02, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13, 1_14, 1_15, 1_16, 1_17, 1_18, 1_19, 1_20, 1_21, 1_22, 1_23, 1_24 |
Sub2 | 0_01, 0_02, 0_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13, 1_14, 1_15, 1_16, 1_17, 1_18, 1_19, 1_20, 1_21, 1_22, 1_23, 1_24, 2_25, 2_26, 2_27, 2_28, 2_29, 2_30, 2_31, 2_32, 2_33, 2_34, 2_35, 2_36, 2_37, 2_38, 2_39, 2_40, 2_41, 2_42, 2_43, 2_44 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_01 | MLE | 644 ms | 406656 KB |
0_02 | TLE | 2138 ms | 406656 KB |
0_03 | TLE | 2142 ms | 406656 KB |
1_04 | MLE | 573 ms | 406656 KB |
1_05 | TLE | 2138 ms | 406656 KB |
1_06 | TLE | 2142 ms | 406656 KB |
1_07 | TLE | 2142 ms | 406656 KB |
1_08 | TLE | 2142 ms | 406656 KB |
1_09 | TLE | 2138 ms | 406656 KB |
1_10 | TLE | 2142 ms | 406656 KB |
1_11 | TLE | 2142 ms | 406656 KB |
1_12 | TLE | 2138 ms | 406656 KB |
1_13 | TLE | 2142 ms | 406656 KB |
1_14 | TLE | 2142 ms | 406656 KB |
1_15 | TLE | 2142 ms | 406656 KB |
1_16 | TLE | 2142 ms | 406656 KB |
1_17 | TLE | 2143 ms | 406656 KB |
1_18 | TLE | 2142 ms | 406656 KB |
1_19 | TLE | 2142 ms | 406656 KB |
1_20 | TLE | 2142 ms | 406656 KB |
1_21 | TLE | 2142 ms | 406656 KB |
1_22 | TLE | 2142 ms | 406656 KB |
1_23 | TLE | 2142 ms | 406656 KB |
1_24 | TLE | 2140 ms | 406656 KB |
2_25 | TLE | 2142 ms | 406656 KB |
2_26 | TLE | 2142 ms | 406656 KB |
2_27 | TLE | 2142 ms | 406656 KB |
2_28 | TLE | 2138 ms | 406656 KB |
2_29 | TLE | 2139 ms | 406656 KB |
2_30 | TLE | 2142 ms | 406656 KB |
2_31 | TLE | 2138 ms | 406656 KB |
2_32 | TLE | 2142 ms | 406656 KB |
2_33 | TLE | 2138 ms | 406656 KB |
2_34 | TLE | 2142 ms | 406656 KB |
2_35 | TLE | 2142 ms | 406656 KB |
2_36 | TLE | 2142 ms | 406656 KB |
2_37 | TLE | 2142 ms | 406656 KB |
2_38 | TLE | 2142 ms | 406656 KB |
2_39 | TLE | 2142 ms | 406656 KB |
2_40 | TLE | 2138 ms | 406656 KB |
2_41 | TLE | 2142 ms | 406656 KB |
2_42 | TLE | 2142 ms | 406656 KB |
2_43 | TLE | 2141 ms | 406656 KB |
2_44 | TLE | 2142 ms | 406656 KB |