# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
223250 | 2020-04-15T06:15:49 Z | dantoh000 | Trener (COCI20_trener) | C++14 | 1911 ms | 143560 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mod = 1000000007; int n,k; ll KEY = 93993939; ll f[55]; int v[26]; unordered_map<ll,int> ct; ll HASH(string s){ ll res = 0; for (int i = 0; i < s.size(); i++){ res = ((res*KEY) + v[s[i]-'a'])%mod; } return res; } ll a[55][1505]; int dp[2][1505]; bool can(ll a, ll b, int len){ for (int i = 0; i < 26; i++){ if ((a*KEY + v[i])%mod == b || (a + i*f[len])%mod == b) return true; } return false; } int main(){ iota(v,v+26,1); random_shuffle(v,v+26); //for (int i = 0; i < 26; i++) printf("%d ",v[i]); f[0] = 1; for (int i = 1; i <= 50; i++){ f[i] = (f[i-1]*KEY)%mod; } scanf("%d%d",&n,&k); for (int i = 1; i <= n; i++){ for (int j = 1; j <= k; j++){ string s; cin >> s; a[i][j] = HASH(s); //cout << s << " " << a[i][j] << endl; } } for (int i = 1; i <= k; i++) { ct[a[n][i]]++; dp[n&1][i]++; } ll ans = 0; for (int i = n-1; i >= 1; i--){ for (int j = 1; j <= k; j++){ ll res = 0; for (int T = 1; T <= 26; T++){ //printf("%lld -> %lld %lld\n",a[i][j],(a[i][j]*KEY + T)%mod,(a[i][j] + T*f[i])%mod); res += ct[(a[i][j]*KEY + T)%mod]; if ((a[i][j] + T*f[i])%mod != (a[i][j]*KEY + T)%mod) res += ct[(a[i][j] + T*f[i])%mod]; } res %= mod; dp[i&1][j] = res; ct[a[i][j]] += res; if (i == 1) ans += res; ct[a[i][j]] %= mod; } for (int j = 1; j <= k; j++){ ct[a[i+1][j]] += mod-dp[1-i&1][j]; ct[a[i+1][j]] %= mod; } } printf("%d",ans%mod); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 512 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 79 ms | 12604 KB | Output is correct |
2 | Correct | 90 ms | 12572 KB | Output is correct |
3 | Correct | 83 ms | 12604 KB | Output is correct |
4 | Correct | 16 ms | 640 KB | Output is correct |
5 | Correct | 48 ms | 8120 KB | Output is correct |
6 | Correct | 50 ms | 8124 KB | Output is correct |
7 | Correct | 16 ms | 768 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 512 KB | Output is correct |
4 | Correct | 5 ms | 384 KB | Output is correct |
5 | Correct | 79 ms | 12604 KB | Output is correct |
6 | Correct | 90 ms | 12572 KB | Output is correct |
7 | Correct | 83 ms | 12604 KB | Output is correct |
8 | Correct | 16 ms | 640 KB | Output is correct |
9 | Correct | 48 ms | 8120 KB | Output is correct |
10 | Correct | 50 ms | 8124 KB | Output is correct |
11 | Correct | 16 ms | 768 KB | Output is correct |
12 | Incorrect | 1911 ms | 143560 KB | Output isn't correct |
13 | Halted | 0 ms | 0 KB | - |