Submission #391679

# Submission time Handle Problem Language Result Execution time Memory
391679 2021-04-19T14:09:37 Z phathnv Trener (COCI20_trener) C++11
110 / 110
54 ms 6336 KB
#include <bits/stdc++.h>

#define mp make_pair
#define X first
#define Y second
#define taskname "TRENER"

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

const int N = 51;
const int K = 1501;
const int base = 163;
const int MOD = 1e9 + 7;

int n, k;
char a[N][K][N];
ll hashed[N][K][3], pw[N];
int dp[N][K];

void readInput(){
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= k; j++)
            scanf("%s", a[i][j] + 1);
}

void prepare(){
    pw[0] = 1;
    for(int i = 1; i <= n; i++)
        pw[i] = pw[i - 1] * base;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= k; j++){
            ll val = 0;
            for(int p = 1; p < i; p++)
                val = val * base + a[i][j][p];
            hashed[i][j][0] = val;
            val = val * base + a[i][j][i];
            hashed[i][j][1] = val - a[i][j][1] * pw[i - 1];
            hashed[i][j][2] = val;
        }
}

void add(int &x, const int &y){
    x += y;
    x -= (x >= MOD) * MOD;
}

void solve(){
    for(int i = 1; i <= k; i++)
        dp[1][i] = 1;
    for(int i = 2; i <= n; i++){
        map <ll, int> d;
        for(int j = 1; j <= k; j++)
            add(d[hashed[i - 1][j][2]], dp[i - 1][j]);
        for(int j = 1; j <= k; j++){
            add(dp[i][j], d[hashed[i][j][0]]);
            if (hashed[i][j][0] != hashed[i][j][1])
                add(dp[i][j], d[hashed[i][j][1]]);
        }
    }
    int res = 0;
    for(int i = 1; i <= k; i++)
        add(res, dp[n][i]);
    printf("%d", res);
}

int main(){
    readInput();
    prepare();
    solve();
    return 0;
}

Compilation message

trener.cpp: In function 'void readInput()':
trener.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
trener.cpp:27:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |             scanf("%s", a[i][j] + 1);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1232 KB Output is correct
2 Correct 4 ms 1228 KB Output is correct
3 Correct 4 ms 1228 KB Output is correct
4 Correct 2 ms 1228 KB Output is correct
5 Correct 3 ms 1228 KB Output is correct
6 Correct 3 ms 1228 KB Output is correct
7 Correct 2 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 4 ms 1232 KB Output is correct
6 Correct 4 ms 1228 KB Output is correct
7 Correct 4 ms 1228 KB Output is correct
8 Correct 2 ms 1228 KB Output is correct
9 Correct 3 ms 1228 KB Output is correct
10 Correct 3 ms 1228 KB Output is correct
11 Correct 2 ms 1228 KB Output is correct
12 Correct 52 ms 6176 KB Output is correct
13 Correct 54 ms 6336 KB Output is correct
14 Correct 52 ms 6148 KB Output is correct
15 Correct 53 ms 6260 KB Output is correct
16 Correct 20 ms 6112 KB Output is correct
17 Correct 46 ms 6212 KB Output is correct
18 Correct 44 ms 6196 KB Output is correct
19 Correct 44 ms 6216 KB Output is correct
20 Correct 45 ms 6212 KB Output is correct
21 Correct 46 ms 6120 KB Output is correct
22 Correct 21 ms 6092 KB Output is correct