Submission #770301

# Submission time Handle Problem Language Result Execution time Memory
770301 2023-07-01T05:14:39 Z Amylopectin Copy and Paste 3 (JOI22_copypaste3) C++14
25 / 100
3000 ms 2568 KB
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;
const long long mxn = 3e3 + 10;
// const long long mxn = 20;
char s[mxn] = {};
long long c1,c2,c3,u[mxn] = {},rev[mxn] = {},dp[mxn][mxn] = {};
long long re(long long cl,long long cr)
{
    if(dp[cl][cr] != 0)
    {
        return dp[cl][cr];
    }
    long long i,j,k,o,n = cr - cl + 1,cn,cm,cou,cma = 1,fmi = -1,cmi;
    for(i=cl; i<=cr; i++)
    {
        u[i] = 0;
    }
    fmi = c1 * n;
    for(i=n/2; i>0; i--)
    {
        cma = 1;
        for(j=cl; j<=cl+n - i*2; j++)
        {
            if(u[j] != i)
            {
                cou = 0;
                cn = j;
                rev[j] = j;
                for(k=j+1; k<j+i; k++)
                {
                    while(1)
                    {
                        if(s[k] == s[cn])
                        {
                            rev[k] = cn+1;
                            cn++;
                            break;
                        }
                        if(cn == j)
                        {
                            rev[k] = j;
                            break;
                        }
                        cn = rev[cn-1];
                    }
                }
                cn = j;
                for(k=j; k<=cr; k++)
                {
                    while(1)
                    {
                        if(s[k] == s[cn])
                        {
                            cn++;
                            break;
                        }
                        if(cn == j)
                        {
                            break;
                        }
                        cn = rev[cn-1];
                    }
                    if(cn == j+i)
                    {
                        u[k-i+1] = i;
                        cn = rev[cn-1];
                    }
                }
                cn = j;
                for(k=j; k<=cr; k++)
                {
                    while(1)
                    {
                        if(s[k] == s[cn])
                        {
                            cn++;
                            break;
                        }
                        if(cn == j)
                        {
                            break;
                        }
                        cn = rev[cn-1];
                    }
                    if(cn == j+i)
                    {
                        cou ++;
                        cn = j;
                    }
                }
                // if(fmi == -1)
                // {
                //     fmi = re(j,j+i-1) + c2 + cou * c3 + c1 * (n-cou*i);
                // }
                // else 
                // {
                    cmi = re(j,j+i-1) + c2 + cou * c3 + c1 * (n-cou*i);
                    if(fmi > cmi)
                    {
                        fmi = cmi;
                    }
                // }
                // if(cou > cma)
                // {
                //     cma = cou;
                // }
            }
        }
    }
    dp[cl][cr] = fmi;
    return fmi;
}
int main()
{
    long long i,j,m,n;
    scanf("%lld %s %lld %lld %lld",&n,&s,&c1,&c2,&c3);
    re(0,n-1);
    printf("%lld",dp[0][n-1]);
    return 0;
}

Compilation message

copypaste3.cpp: In function 'long long int re(long long int, long long int)':
copypaste3.cpp:16:21: warning: unused variable 'o' [-Wunused-variable]
   16 |     long long i,j,k,o,n = cr - cl + 1,cn,cm,cou,cma = 1,fmi = -1,cmi;
      |                     ^
copypaste3.cpp:16:42: warning: unused variable 'cm' [-Wunused-variable]
   16 |     long long i,j,k,o,n = cr - cl + 1,cn,cm,cou,cma = 1,fmi = -1,cmi;
      |                                          ^~
copypaste3.cpp:16:49: warning: variable 'cma' set but not used [-Wunused-but-set-variable]
   16 |     long long i,j,k,o,n = cr - cl + 1,cn,cm,cou,cma = 1,fmi = -1,cmi;
      |                                                 ^~~
copypaste3.cpp: In function 'int main()':
copypaste3.cpp:119:18: warning: format '%s' expects argument of type 'char*', but argument 3 has type 'char (*)[3010]' [-Wformat=]
  119 |     scanf("%lld %s %lld %lld %lld",&n,&s,&c1,&c2,&c3);
      |                 ~^                    ~~
      |                  |                    |
      |                  char*                char (*)[3010]
copypaste3.cpp:118:15: warning: unused variable 'i' [-Wunused-variable]
  118 |     long long i,j,m,n;
      |               ^
copypaste3.cpp:118:17: warning: unused variable 'j' [-Wunused-variable]
  118 |     long long i,j,m,n;
      |                 ^
copypaste3.cpp:118:19: warning: unused variable 'm' [-Wunused-variable]
  118 |     long long i,j,m,n;
      |                   ^
copypaste3.cpp:119:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  119 |     scanf("%lld %s %lld %lld %lld",&n,&s,&c1,&c2,&c3);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 304 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Execution timed out 3031 ms 2568 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 304 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 392 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 432 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 304 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 312 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 308 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 304 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 392 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 432 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 304 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 312 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 308 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 18 ms 596 KB Output is correct
41 Correct 29 ms 808 KB Output is correct
42 Correct 1135 ms 1148 KB Output is correct
43 Correct 1123 ms 1120 KB Output is correct
44 Correct 1032 ms 1064 KB Output is correct
45 Correct 880 ms 1184 KB Output is correct
46 Correct 804 ms 1080 KB Output is correct
47 Correct 577 ms 908 KB Output is correct
48 Correct 831 ms 944 KB Output is correct
49 Correct 817 ms 1140 KB Output is correct
50 Correct 813 ms 1132 KB Output is correct
51 Correct 546 ms 896 KB Output is correct
52 Correct 609 ms 968 KB Output is correct
53 Correct 818 ms 1180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 304 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 392 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 432 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 304 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 312 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 308 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 18 ms 596 KB Output is correct
41 Correct 29 ms 808 KB Output is correct
42 Correct 1135 ms 1148 KB Output is correct
43 Correct 1123 ms 1120 KB Output is correct
44 Correct 1032 ms 1064 KB Output is correct
45 Correct 880 ms 1184 KB Output is correct
46 Correct 804 ms 1080 KB Output is correct
47 Correct 577 ms 908 KB Output is correct
48 Correct 831 ms 944 KB Output is correct
49 Correct 817 ms 1140 KB Output is correct
50 Correct 813 ms 1132 KB Output is correct
51 Correct 546 ms 896 KB Output is correct
52 Correct 609 ms 968 KB Output is correct
53 Correct 818 ms 1180 KB Output is correct
54 Execution timed out 3005 ms 1300 KB Time limit exceeded
55 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 304 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Execution timed out 3031 ms 2568 KB Time limit exceeded
14 Halted 0 ms 0 KB -