제출 #863064

#제출 시각아이디문제언어결과실행 시간메모리
863064boris_mihovCopy and Paste 3 (JOI22_copypaste3)C++17
25 / 100
3100 ms32320 KiB
#include <algorithm> #include <iostream> #include <numeric> #include <cassert> #include <vector> typedef long long llong; const int MAXN = 2500 + 10; const int INF = 1e9; int n; char s[MAXN]; llong a, b, c; llong dp[MAXN][MAXN]; bool bl[MAXN][MAXN]; llong f(int l, int r) { // std::cout << "call: " << l << ' ' << r << '\n' << std::flush; if (l == r) { return a; } if (bl[l][r]) { return dp[l][r]; } bl[l][r] = true; dp[l][r] = std::min(f(l + 1, r) + a, f(l, r - 1) + a); int kmpF[MAXN]; kmpF[l] = 0; for (int prefix = l ; prefix < r ; ++prefix) { if (prefix != l) { kmpF[prefix] = kmpF[prefix - 1]; while (kmpF[prefix] > 0 && s[l + kmpF[prefix]] != s[prefix]) { // std::cout << "here22: " << prefix << ' ' << kmpF[prefix] << '\n'; kmpF[prefix] = kmpF[l + kmpF[prefix] - 1]; } if (s[l + kmpF[prefix]] == s[prefix]) { kmpF[prefix]++; // std::cout << "incr: " << prefix << ' ' << kmpF[prefix] << '\n'; } } int ptr = 0; llong cnt = 1; llong cost = f(l, prefix) + b; for (int j = prefix + 1 ; j <= r ; ++j) { if (s[j] == s[l + ptr]) { ptr++; if (ptr == prefix - l + 1) { cnt++; ptr = 0; } } else { while (ptr > 0 && s[l + ptr] != s[j]) { ptr = kmpF[l + ptr - 1]; } if (s[j] == s[l + ptr]) { ptr++; } } } dp[l][r] = std::min(dp[l][r], cost + cnt * c + (r - l + 1) * a - (prefix - l + 1) * cnt * a); } return dp[l][r]; } void solve() { std::cout << f(1, n) << '\n'; } void input() { std::cin >> n; std::cin >> s + 1; std::cin >> a >> b >> c; } void fastIOI() { std::ios_base :: sync_with_stdio(0); std::cout.tie(nullptr); std::cin.tie(nullptr); } int main() { fastIOI(); input(); solve(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

copypaste3.cpp: In function 'void input()':
copypaste3.cpp:94:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   94 |     std::cin >> s + 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...