# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
530962 | 2022-02-27T08:19:48 Z | Tenis0206 | Trener (COCI20_trener) | C++11 | 78 ms | 1728 KB |
#include <bits/stdc++.h> #define int long long using namespace std; const int Mod = 1e9 + 7; const int Mh = 1e9 + 7; const int b = 29; int n,k; int dp[1505]; string s[1505]; map<int,int> dps,fc; int put[115]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>k; put[0] = 1; for(int i=1;i<=n;i++) { put[i] = 1LL * put[i-1] * b % Mh; } for(int j=1; j<=k; j++) { cin>>s[j]; int Hash = 0; for(auto it : s[j]) { Hash = (1LL * Hash * b + (it - 'a' + 1)) % Mh; } ++dps[Hash]; } for(int i=2; i<=n; i++) { for(int j=1; j<=k; j++) { dp[j] = 0; } for(int j=1; j<=k; j++) { cin>>s[j]; fc.clear(); int Hash = 0; for(int dr=0; dr<i-1; dr++) { Hash = (1LL * Hash * b + (s[j][dr] - 'a' + 1)) % Mh; } if(!fc[Hash]) { dp[j] += dps[Hash]; dp[j] %= Mod; } ++fc[Hash]; for(int st=1; st+i-2<s[j].size(); st++) { int dr = st + i - 2; Hash = (1LL * Hash * b + (s[j][dr] - 'a' + 1)) % Mh; Hash = (Hash - (s[j][st-1] - 'a' + 1) * put[i-1] % Mh + Mh) % Mh; if(!fc[Hash]) { dp[j] += dps[Hash]; dp[j] %= Mod; } ++fc[Hash]; } } dps.clear(); for(int j=1; j<=k; j++) { int Hash = 0; for(auto it : s[j]) { Hash = (1LL * Hash * b + (it - 'a' + 1)) % Mh; } dps[Hash] += dp[j]; dps[Hash] %= Mod; } } int rez = 0; for(int j=1; j<=k; j++) { rez += dp[j]; rez %= Mod; } cout<<rez<<'\n'; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 0 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 0 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 332 KB | Output is correct |
3 | Correct | 4 ms | 332 KB | Output is correct |
4 | Correct | 2 ms | 332 KB | Output is correct |
5 | Correct | 4 ms | 332 KB | Output is correct |
6 | Correct | 4 ms | 332 KB | Output is correct |
7 | Correct | 2 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 0 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 0 ms | 332 KB | Output is correct |
5 | Correct | 4 ms | 384 KB | Output is correct |
6 | Correct | 4 ms | 332 KB | Output is correct |
7 | Correct | 4 ms | 332 KB | Output is correct |
8 | Correct | 2 ms | 332 KB | Output is correct |
9 | Correct | 4 ms | 332 KB | Output is correct |
10 | Correct | 4 ms | 332 KB | Output is correct |
11 | Correct | 2 ms | 332 KB | Output is correct |
12 | Correct | 76 ms | 1380 KB | Output is correct |
13 | Correct | 71 ms | 1668 KB | Output is correct |
14 | Correct | 78 ms | 1728 KB | Output is correct |
15 | Correct | 69 ms | 1704 KB | Output is correct |
16 | Correct | 31 ms | 1476 KB | Output is correct |
17 | Correct | 69 ms | 1616 KB | Output is correct |
18 | Correct | 70 ms | 1588 KB | Output is correct |
19 | Correct | 71 ms | 1640 KB | Output is correct |
20 | Correct | 61 ms | 1636 KB | Output is correct |
21 | Correct | 60 ms | 1644 KB | Output is correct |
22 | Correct | 32 ms | 1520 KB | Output is correct |