Submission #1309225

#TimeUsernameProblemLanguageResultExecution timeMemory
1309225thuhienneCopy and Paste 3 (JOI22_copypaste3)C++20
57 / 100
3096 ms49748 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define thuhien "" #define re exit(0); #define hash __hash__ int n; string s; int a,b,c; const ll mod = 1e9 + 7,base = 31; ll hash[2509],power[2509]; void createhash() { power[0] = 1; for (int i = 1;i <= n;i++) { hash[i] = (hash[i - 1] * base + s[i] - 'a' + 1) % mod; power[i] = power[i - 1] * base % mod; } } int gethash(int l,int r) { return (hash[r] - hash[l - 1] * power[r - l + 1] + mod * mod) % mod; } ll dp[2509][2509]; int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); if (fopen(thuhien".inp","r")) { freopen(thuhien".inp","r",stdin); freopen(thuhien".out","w",stdout); } cin >> n >> s >> a >> b >> c; s = " " + s; createhash(); memset(dp,0x3f3f,sizeof(dp)); for (int i = 1;i <= n;i++) dp[i][i] = a; for (int len = 1;len <= n;len++) { for (int i = 1;i + len - 1 <= n;i++) { int l = i,r = i + len - 1; dp[l][r] = min(dp[l][r],min(dp[l + 1][r],dp[l][r - 1]) + a); } for (int i = 1;i + len - 1 <= n;i++) { int l = i,r = i + len - 1; int cnt = 1,last = r; for (int j = r + 1;j + len - 1 <= n;j++) { int x = j,y = j + len - 1; if (gethash(l,r) != gethash(x,y)) continue; if (x > last) { cnt++; last = y; } dp[l][y] = min(dp[l][y],dp[l][r] + b + 1ll * c * cnt + 1ll * (y - l + 1 - cnt * len) * a); // cout << ":D " << l << " " << r << " " << dp[l][r] << '\n'; } } } cout << dp[1][n]; }

Compilation message (stderr)

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