Submission #556068

#TimeUsernameProblemLanguageResultExecution timeMemory
556068600MihneaCopy and Paste 3 (JOI22_copypaste3)C++17
15 / 100
3060 ms19816 KiB
#include <bits/stdc++.h> bool home = 1; using namespace std; typedef long long ll; const int N=2500+7; const ll INF=(ll)1e18+7; int n; int v[N]; int lcp[N][N]; ll a, b, c, dp[N][N]; signed main() { #ifdef ONLINE_JUDGE home = 0; #endif home=0; if (home) { freopen("I_am_iron_man", "r", stdin); } else { ios::sync_with_stdio(0); cin.tie(0); } cin>>n; { string str; cin>>str; assert((int)str.size()==n); for(int i=1;i<=n;i++){ v[i]=str[i-1]-'a'; assert(0<=v[i]&&v[i]<26); } cin>>a>>b>>c; } for (int i=n;i>=1;i--) { for (int j=n;j>=1;j--) { if (v[i]==v[j]){ lcp[i][j]=1+lcp[i+1][j+1]; } } } for (int l=n;l>=1;l--) { for (int r=l;r<=n;r++) { dp[l][r]=a*(r-l+1); for (int i=l;i<=r;i++){ for(int j=i;j<=r;j++){ int len=j-i+1,cnt=0; int k=l; while (k+len-1<=r) { if (lcp[k][i]>=len) { k+=len; cnt++; }else{ k++; } } dp[l][r]=min(dp[l][r],dp[i][j]+b+c*cnt+a*((r-l+1)-cnt*len)); } } } } cout<<dp[1][n]<<"\n"; }

Compilation message (stderr)

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     freopen("I_am_iron_man", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...