Submission #1031233

#TimeUsernameProblemLanguageResultExecution timeMemory
1031233adaawfCopy and Paste 3 (JOI22_copypaste3)C++17
57 / 100
60 ms71632 KiB
#include <iostream> #include <map> using namespace std; long long int c[3005], p[3005], f[3005][3005], g[1005][1005], mod = 1e9 + 7, b = 177013; long long int check(int i, int j) { return (c[j] - c[i - 1] * p[j - i + 1] % mod + mod) % mod; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, x, y, z; string s; cin >> n >> s >> x >> y >> z; s = " " + s; p[0] = 1; for (int i = 1; i <= n; i++) { c[i] = (c[i - 1] * b + s[i] - 'a' + 1) % mod; p[i] = p[i - 1] * b % mod; } for (int d = 1; d <= n; d++) { map<long long int, int> m; for (int i = n - d + 1; i >= 1; i--) { int j = i + d - 1; g[i][j] = 1e18; long long int h = check(i, j); if (m.count(h)) f[i][j] = m[h]; else f[i][j] = 0; if (j + d - 1 <= n) m[check(j, j + d - 1)] = j; } } for (int d = 1; d <= n; d++) { for (int i = 1; i <= n - d + 1; i++) { int j = i + d - 1; g[i][j] = min(g[i][j], x * d); g[i][j] = min(g[i][j], min(g[i + 1][j], g[i][j - 1]) + x); int h = i, l = 1; while (1) { h = f[h][h + d - 1]; if (h == 0) break; int k = h + d - 1; l++; g[i][k] = min(g[i][k], g[i][j] + y + x * (k - i + 1 - l * d) + l * z); } } } cout << g[1][n]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...