제출 #391679

#제출 시각아이디문제언어결과실행 시간메모리
391679phathnvTrener (COCI20_trener)C++11
110 / 110
54 ms6336 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...