| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 899062 | LucaIlie | Copy and Paste 3 (JOI22_copypaste3) | C++17 | 937 ms | 73540 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2500;
int z[2 * MAX_N + 2], nextPos[MAX_N + 1][MAX_N + 1];
long long dp[MAX_N + 1][MAX_N + 1];
int main() {
int n, a, b, c;
string s;
cin >> n >> s >> a >> b >> c;
s = "#" + s;
for ( int l = 1; l <= n; l++ ) {
for ( int r = l; r <= n; r++ )
dp[l][r] = (long long)a * (r - l + 1) + b;
}
string t = s;
for ( int l = n; l >= 1; l-- ) {
t = s[l] + t;
int ls = 0, rs = 0;
for ( int i = 1; i < t.size(); i++ )
z[i] = 0;
for ( int i = 1; i < t.size(); i++ ){
if ( i < rs )
z[i] = min( z[i - ls], rs - i );
while( i + z[i] < t.size() && t[z[i]] == t[i + z[i]] )
z[i]++;
if ( i + z[i] > rs ) {
ls = i;
rs = i + z[i];
}
}
for ( int r = l; r <= n; r++ ) {
int i = n - l + r + 2;
while ( i < t.size() && z[i] < r - l + 1 )
i++;
nextPos[l][r] = i - (n - l + 1);
}
}
for ( int len = 1; len <= n; len++ ) {
for ( int l = 1; l <= n - len + 1; l++ ) {
int r = l + len - 1;
dp[l - 1][r] = min( dp[l - 1][r], dp[l][r] + a );
dp[l][r + 1] = min( dp[l][r + 1], dp[l][r] + a );
long long cost = dp[l][r] + b + c;
int k = l;
while ( nextPos[k][k + len - 1] <= n ) {
cost += (long long)a * (nextPos[k][k + len - 1] - (k + len)) + c;
k = nextPos[k][k + len - 1];
dp[l][k + len - 1] = min( dp[l][k + len - 1], cost );
}
}
}
cout << dp[1][n] - b << "\n";
return 0;
}컴파일 시 표준 에러 (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... | ||||
