Submission #720523

#TimeUsernameProblemLanguageResultExecution timeMemory
720523Abrar_Al_SamitCopy and Paste 3 (JOI22_copypaste3)C++17
100 / 100
642 ms49648 KiB
#include<bits/stdc++.h> using namespace std; const int nax = 2503; const long long INF = 1e18; const int P = 31; const int M = 1e9 + 11; int n; string s; long long A, B, C; long long dp[nax][nax]; long long hv[nax]; long long pw[nax]; int nxt[nax]; int get(int l, int r) { long long ret = hv[r] - hv[l-1]; if(ret<0) ret += M; ret = (ret * pw[n-r]) % M; return ret; } void PlayGround() { cin>>n>>s>>A>>B>>C; s = '@' + s; pw[0] = 1; for(int i=1; i<=n; ++i) { pw[i] = (pw[i-1] * P) % M; hv[i] = (pw[i] * (s[i]-'a'+1)) + hv[i-1]; hv[i] %= M; } for(int i=1; i<=n; ++i) { for(int j=1; j<=n; ++j) { dp[i][j] = INF; } dp[i][i] = A; } for(int un=1; un<=n; ++un) { memset(nxt, -1, sizeof nxt); unordered_map<int, vector<int>>app; for(int i=1; i+un-1<=n; ++i) if(un>1) { dp[i][i+un-1] = min(dp[i][i+un-1], min(dp[i+1][i+un-1], dp[i][i+un-2]) + A); } for(int i=n-un+1; i>0; --i) { int crval = get(i, i+un-1); auto &v = app[crval]; if(v.empty()) v.push_back(1); v.push_back(i); while(v[0]+1<v.size() && v[v[0]+1]>i+un-1) ++v[0]; if(v[v[0]]<=i+un-1) nxt[i] = -1; else nxt[i] = v[v[0]]; } for(int i=1; i<=n; ++i) { for(int j=nxt[i], cnt=2; j!=-1; j=nxt[j], ++cnt) { dp[i][j+un-1] = min(dp[i][j+un-1], dp[i][i+un-1]+B+cnt*C + (j+un-1-i+1 - cnt*un) * A); } } } cout<<dp[1][n]<<'\n'; // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); PlayGround(); return 0; }

Compilation message (stderr)

copypaste3.cpp: In function 'void PlayGround()':
copypaste3.cpp:56:16: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |    while(v[0]+1<v.size() && v[v[0]+1]>i+un-1)
#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...