Submission #883160

# Submission time Handle Problem Language Result Execution time Memory
883160 2023-12-04T16:39:18 Z LucaIlie Copy and Paste 3 (JOI22_copypaste3) C++17
0 / 100
1 ms 2648 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 + 1][r], dp[l][r - 1] ) + 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 + (len / d) * c );

                    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 + (len / d) * c );

                    d = len / d;
                }
            }

            //printf( "%d %d %lld\n", l, r, dp[l][r] );
        }
    }

    cout << dp[0][n - 1];

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 1 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 1 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 1 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 1 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 1 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -