Submission #711284

#TimeUsernameProblemLanguageResultExecution timeMemory
711284kostia244Copy and Paste 3 (JOI22_copypaste3)C++17
100 / 100
503 ms102572 KiB
#include<bits/stdc++.h> #define all(x) begin(x), end(x) using namespace std; using ll = long long; const int N = 2525; int n; ll a, b, c; ll dp[N][N], jump[N][N], best[N]; string s; int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> s >> a >> b >> c; vector<int> sa(n); iota(all(sa), 0); memset(jump, -1, sizeof jump); auto dfs = [&](auto self, vector<int> &p, int dep) -> void { if(p.size() < 2) return; vector<int> ch[26]; int j = 0; for(auto i : p) { if(i + dep < s.size()) ch[s[i + dep] - 'a'].push_back(i); if(dep) { while(p[j] + dep - 1 < i) j++; jump[dep][i] = j ? p[j - 1] : -1; } } p.clear(); for(int i = 0; i < 26; i++) { self(self, ch[i], dep + 1); } }; dfs(dfs, sa, 0); for(int r = 0; r < n; r++) { memset(best, 0x3f, sizeof best); for(int l = r; l >= 0; l--) {//copy string best[l] = min(best[l], best[l + 1]); dp[r][l] = min((r > l ? dp[r - 1][l] : 0) + a, (r - l + 1) * a + best[l]); int lst = n + 1, len = r - l + 1, cnt = 0; for(int p = l; p >= 0; p = jump[len][p]) { // if(p + len - 1 < lst && // s.substr(p, len) == s.substr(l, len)) { cnt++; lst = p; best[p] = min(best[p], (-len * a + c) * cnt + dp[r][l] + b); // } } } } cout << dp[n - 1][0] << '\n'; }

Compilation message (stderr)

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:43:17: warning: variable 'lst' set but not used [-Wunused-but-set-variable]
   43 |             int lst = n + 1, len = r - l + 1, cnt = 0;
      |                 ^~~
copypaste3.cpp: In instantiation of 'main()::<lambda(auto:23, std::vector<int>&, int)> [with auto:23 = main()::<lambda(auto:23, std::vector<int>&, int)>]':
copypaste3.cpp:36:19:   required from here
copypaste3.cpp:23:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |             if(i + dep < s.size())
      |                ~~~~~~~~^~~~~~~~~~
#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...