제출 #1271075

#제출 시각아이디문제언어결과실행 시간메모리
1271075tvgkCopy and Paste 3 (JOI22_copypaste3)C++20
30 / 100
150 ms49556 KiB
#include<bits/stdc++.h> using namespace std; #define task "a" #define se second #define fi first #define ll long long #define ii pair<ll, ll> const long mxN = 25e2 + 7, base = 29, MOD = 1e9 + 9; const ll inf = 1e18; int n, nxt[mxN]; string s; ll add, cop, paste, dp[mxN][mxN], hsh[mxN], pw[mxN]; map<int, int> mp; int Get(int u, int v) { return (hsh[u + v - 1] - hsh[u - 1] * pw[v] % MOD + MOD) % MOD; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen(task".INP", "r", stdin); //freopen(task".OUT", "w", stdout); cin >> n; cin >> s; cin >> add >> cop >> paste; s = '-' + s; pw[0] = 1; for (int i = 1; i <= n; i++) { pw[i] = pw[i - 1] * base % MOD; hsh[i] = (hsh[i - 1] * base + s[i] - 'a' + 1) % MOD; for (int j = 1; j <= n; j++) dp[i][j] = inf; } for (int i = 1; i <= n; i++) { mp.clear(); for (int j = n - i + 1; j >= 1; j--) { if (j + i + i - 1 <= n) mp[Get(j + i, i)] = j + i; dp[j][i] = min({dp[j][i], dp[j][i - 1] + add, dp[j + 1][i - 1] + add}); nxt[j] = mp[Get(j, i)]; int tmp = j; ll cur = dp[j][i] + cop + paste; while (nxt[tmp]) { cur += paste + add * (nxt[tmp] - tmp - i); tmp = nxt[tmp]; dp[j][tmp + i - j] = min(dp[j][tmp + i - j], cur); } } } cout << dp[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...