# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
592447 | 79brue | Copy and Paste 3 (JOI22_copypaste3) | C++17 | 779 ms | 82936 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000009;
int n;
ll A, B, C;
char str[2502];
int arr[2502];
ll hashVal[2502][2502];
ll DP[2502][2502];
int nxt[2502];
int main(){
scanf("%d %s %lld %lld %lld", &n, str+1, &A, &B, &C);
for(int i=1; i<=n; i++) arr[i] = str[i] - 'a';
for(int i=1; i<=n; i++){
for(int j=i; j<=n; j++){
hashVal[i][j] = (hashVal[i][j-1] * 1000003 + arr[j]) % MOD;
}
}
for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) DP[i][j] = 1e18;
for(int i=1; i<=n; i++) DP[i][i] = A;
for(int d=0; d<n; d++){
map<ll, int> mp;
for(int i=1; i+d<=n; i++){
int j = i+d;
DP[i][j] = min({DP[i][j], DP[i+1][j]+A, DP[i][j-1]+A});
}
for(int i=n-d; i>=1; i--){
int j = i+d;
if(mp[hashVal[i][j]]) nxt[i] = mp[hashVal[i][j]];
else nxt[i] = 0;
if(j+d<=n) mp[hashVal[j][j+d]] = j;
}
for(int i=1; i+d<=n; i++){
int e = i+d;
int cnt = 1;
while(nxt[e-d]){
e = nxt[e-d]+d;
cnt++;
// printf("Set %d %d to %lld\n", i, e, DP[i][i+d] + B + C * cnt + A * (e-i+1 - cnt*(d+1)));
DP[i][e] = min(DP[i][e], DP[i][i+d] + B + C * cnt + A * (e-i+1 - cnt*(d+1)));
}
// printf("%d %d: %lld\n", i, i+d, DP[i][i+d]);
}
}
printf("%lld", DP[1][n]);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |