Submission #223222

# Submission time Handle Problem Language Result Execution time Memory
223222 2020-04-15T05:34:24 Z cheeheng Trener (COCI20_trener) C++14
110 / 110
152 ms 14200 KB
#include <bits/stdc++.h>
using namespace std;

const long long MOD = 1e9+7;

long long dp[55][1505];
char str[55];

string A[55][1505];

map<string, long long> m[55];

int main(){
    int N, K;
    scanf("%d%d", &N, &K);

    for(int i = 1; i <= N; i ++){
        for(int j = 0; j < K; j ++){
            memset(str, 0, sizeof(str));
            scanf(" %s", str);

            A[i][j] = string(str);

            if(i == 1){
                dp[i][j] = 1;
            }else{
                string str1 = A[i][j].substr(1);
                string str2 = A[i][j].substr(0, i-1);
                //printf("%s %s\n", str1.c_str(), str2.c_str());
                dp[i][j] = 0;
                if(m[i-1].find(str1) != m[i-1].end()){
                    dp[i][j] += m[i-1][str1];
                }

                if(m[i-1].find(str2) != m[i-1].end() && str1 != str2){
                    dp[i][j] += m[i-1][str2];
                }
            }

            dp[i][j] %= MOD;
            if(m[i].find(A[i][j]) == m[i].end()){
                m[i][A[i][j]] = dp[i][j];
            }else{
                m[i][A[i][j]] += dp[i][j];
            }
        }
    }

    long long ans = 0;
    for(int i = 0; i < K; i ++){
        ans += dp[N][i];
    }
    ans %= MOD;

    printf("%lld", ans);
    return 0;
}

Compilation message

trener.cpp: In function 'int main()':
trener.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &K);
     ~~~~~^~~~~~~~~~~~~~~~
trener.cpp:20:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf(" %s", str);
             ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2944 KB Output is correct
2 Correct 6 ms 2944 KB Output is correct
3 Correct 6 ms 2944 KB Output is correct
4 Correct 6 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3840 KB Output is correct
2 Correct 13 ms 3840 KB Output is correct
3 Correct 13 ms 3968 KB Output is correct
4 Correct 8 ms 3328 KB Output is correct
5 Correct 13 ms 3712 KB Output is correct
6 Correct 13 ms 3840 KB Output is correct
7 Correct 8 ms 3328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2944 KB Output is correct
2 Correct 6 ms 2944 KB Output is correct
3 Correct 6 ms 2944 KB Output is correct
4 Correct 6 ms 2944 KB Output is correct
5 Correct 12 ms 3840 KB Output is correct
6 Correct 13 ms 3840 KB Output is correct
7 Correct 13 ms 3968 KB Output is correct
8 Correct 8 ms 3328 KB Output is correct
9 Correct 13 ms 3712 KB Output is correct
10 Correct 13 ms 3840 KB Output is correct
11 Correct 8 ms 3328 KB Output is correct
12 Correct 131 ms 14200 KB Output is correct
13 Correct 139 ms 14108 KB Output is correct
14 Correct 136 ms 14200 KB Output is correct
15 Correct 131 ms 14200 KB Output is correct
16 Correct 38 ms 6008 KB Output is correct
17 Correct 144 ms 12024 KB Output is correct
18 Correct 146 ms 12280 KB Output is correct
19 Correct 152 ms 12024 KB Output is correct
20 Correct 145 ms 12152 KB Output is correct
21 Correct 148 ms 12152 KB Output is correct
22 Correct 40 ms 6008 KB Output is correct