# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
391679 | phathnv | Trener (COCI20_trener) | C++11 | 54 ms | 6336 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |