Submission #883173

# Submission time Handle Problem Language Result Execution time Memory
883173 2023-12-04T17:12:52 Z LucaIlie Copy and Paste 3 (JOI22_copypaste3) C++17
1 / 100
3000 ms 37916 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2500;
long long dp[MAX_N][MAX_N];

int main() {
    int n, a, b, c;
    string s;

    cin >> n >> s >> a >> b >> c;

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

    for ( int len = 2; len <= n; len++ ) {
        for ( int l = 0; l <= n - len; l++ ) {
            int r = l + len - 1;
            dp[l][r] = min( dp[l][r - 1], dp[l + 1][r] ) + a;
            for ( int d = 1; d * d <= len; d++ ) {
                if ( len % d == 0 ) {
                    bool ok;

                    ok = true;
                    for ( int i = l; i <= r - d; i++ )
                        ok &= (s[i] == s[i + d]);
                    if ( ok )
                        dp[l][r] = min( dp[l][r], dp[l][l + d - 1] + b + (long long)c * (len / d) );

                    d = len / d;
                    ok = true;
                    for ( int i = l; i <= r - d; i++ )
                        ok &= (s[i] == s[i + d]);
                    if ( ok )
                        dp[l][r] = min( dp[l][r], dp[l][l + d - 1] + b + (long long)c * (len / d) );

                    d = len / d;
                }
            }
        }
    }

    long long ans = LONG_LONG_MAX;
    for ( int l = 0; l < n; l++ ) {
        for ( int r = l; r < n; r++ )
            ans = min( ans, dp[l][r] + (long long)a * (n - (r - l + 1)) );
    }
    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 388 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 3079 ms 37916 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 388 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Incorrect 1 ms 2396 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 388 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Incorrect 1 ms 2396 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 388 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Incorrect 1 ms 2396 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 388 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Execution timed out 3079 ms 37916 KB Time limit exceeded
14 Halted 0 ms 0 KB -