Submission #838661


Source Code Expand

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


const int maxn = 300+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 400
Code Size 2115 Byte
Status WA
Exec Time 2105 ms
Memory 2816 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 400 / 400 0 / 400
Status
AC × 2
TLE × 1
AC × 23
AC × 23
WA × 2
TLE × 2
RE × 17
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 AC 8 ms 2688 KB
0_02 AC 43 ms 2688 KB
0_03 TLE 2105 ms 2688 KB
1_04 AC 7 ms 2688 KB
1_05 AC 39 ms 2688 KB
1_06 AC 40 ms 2688 KB
1_07 AC 77 ms 2688 KB
1_08 AC 82 ms 2688 KB
1_09 AC 82 ms 2688 KB
1_10 AC 80 ms 2688 KB
1_11 AC 46 ms 2688 KB
1_12 AC 80 ms 2688 KB
1_13 AC 80 ms 2688 KB
1_14 AC 78 ms 2688 KB
1_15 AC 42 ms 2688 KB
1_16 AC 81 ms 2688 KB
1_17 AC 57 ms 2688 KB
1_18 AC 75 ms 2816 KB
1_19 AC 57 ms 2688 KB
1_20 AC 14 ms 2688 KB
1_21 AC 37 ms 2688 KB
1_22 AC 15 ms 2688 KB
1_23 AC 72 ms 2688 KB
1_24 AC 54 ms 2688 KB
2_25 WA 761 ms 2688 KB
2_26 WA 872 ms 2688 KB
2_27 RE 811 ms 2688 KB
2_28 RE 345 ms 2688 KB
2_29 RE 346 ms 2688 KB
2_30 RE 341 ms 2688 KB
2_31 RE 346 ms 2688 KB
2_32 RE 342 ms 2688 KB
2_33 RE 347 ms 2688 KB
2_34 RE 344 ms 2688 KB
2_35 RE 344 ms 2688 KB
2_36 RE 344 ms 2688 KB
2_37 RE 343 ms 2688 KB
2_38 RE 342 ms 2688 KB
2_39 RE 344 ms 2688 KB
2_40 RE 346 ms 2688 KB
2_41 TLE 2105 ms 2688 KB
2_42 RE 352 ms 2688 KB
2_43 RE 342 ms 2688 KB
2_44 RE 339 ms 2688 KB