제출 #863052

#제출 시각아이디문제언어결과실행 시간메모리
863052boris_mihovCopy and Paste 3 (JOI22_copypaste3)C++17
15 / 100
3079 ms14808 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; int a, b, c; char s[MAXN]; llong dp[MAXN][MAXN]; bool bl[MAXN][MAXN]; int kmpF[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); for (int prefix = l ; prefix < r ; ++prefix) { // std::cout << "here: " << l << ' ' << r << ' ' << prefix << '\n'; // kmpF[prefix - l + 1] = kmpF[prefix - l]; // while (kmpF[prefix - l + 1] > 0 && s[l + kmpF[prefix - l + 1]] != s[prefix]) // { // kmpF[prefix - l + 1] = kmpF[l + kmpF[prefix - l + 1] - 1]; // } // if (s[l + kmpF[prefix - l + 1]] == s[prefix]) llong cost = f(l, prefix) + b + c; for (int j = prefix + 1 ; j <= r ; ++j) { bool match = true; for (int k = 0 ; k <= prefix - l ; ++k) { if (s[l + k] != s[j + k]) { match = false; break; } } if (match) { cost += c; j += prefix - l; } else { cost += a; } } dp[l][r] = std::min(dp[l][r], cost); } 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:82:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   82 |     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...