Submission #1061884

# Submission time Handle Problem Language Result Execution time Memory
1061884 2024-08-16T14:45:22 Z sleepntsheep Copy and Paste 3 (JOI22_copypaste3) C++17
0 / 100
3000 ms 49756 KB
#pragma GCC optimize("O3,unroll-loops")

#include <deque>
#include <string>
#include <iostream>
#include <map>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
template <typename T>
using ve = vector<T>;
template <typename T>
using bs = basic_string<T>;

const int N = 2505;

int n, nxt[N][N], z[N];
ll dp[N][N], a, b, c;
char s[N];

void init() {
    memset(dp, 63, sizeof dp);

    for (int i = 1; i <= n; ++i)
        dp[i][i] = a;

    for (int i = 1; i <= n; ++i) {
        z[i] = n - i + 1;
        for (int k = i + 1, l = i, r = i + 1; k <= n; ++k) {
            z[k] = 0;
            if (k < r) z[k] = min(z[k - l], r - k);
            while (k + z[k] <= n && s[k] == s[i + k + z[k]]) ++z[k];
            if (k + z[k] > r) l = k, r = k + z[k];
        }
        for (int p = i, j = i; j <= n; ++j) {
            while (p <= n && (p <= j || z[p - i] < j - i + 1)) ++p;
            nxt[i][j] = p;
        }
    }
}

int main() {
    scanf("%d%s%lld%lld%lld", &n, s + 1, &a, &b, &c);

    init();

    for (int l = 1; l <= n; ++l) {
        for (int i = 1, j = l; j <= n; ++i, ++j) {
            if (i < j) {
                dp[i][j] = min(dp[i][j], dp[i + 1][j] + a);
                dp[i][j] = min(dp[i][j], dp[i][j - 1] + a);
            }
            for (int at = i, cnt = 1; at <= n; ++cnt, at = nxt[at][at + l - 1]) {
                int jj = at + l - 1;
                dp[i][jj] = min(dp[i][jj], dp[i][j] + b + cnt * c + (jj - i + 1 - cnt * l) * a);
            }
        }
    }

    printf("%lld", dp[1][n]);
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |     scanf("%d%s%lld%lld%lld", &n, s + 1, &a, &b, &c);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 49756 KB Output is correct
2 Correct 5 ms 49756 KB Output is correct
3 Incorrect 5 ms 49756 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3051 ms 49756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 49756 KB Output is correct
2 Correct 5 ms 49756 KB Output is correct
3 Incorrect 5 ms 49756 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 49756 KB Output is correct
2 Correct 5 ms 49756 KB Output is correct
3 Incorrect 5 ms 49756 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 49756 KB Output is correct
2 Correct 5 ms 49756 KB Output is correct
3 Incorrect 5 ms 49756 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 49756 KB Output is correct
2 Correct 5 ms 49756 KB Output is correct
3 Incorrect 5 ms 49756 KB Output isn't correct
4 Halted 0 ms 0 KB -