답안 #550747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
550747 2022-04-19T01:53:33 Z lkh3happy Copy and Paste 3 (JOI22_copypaste3) C++14
62 / 100
1593 ms 57860 KB
#include <stdio.h>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;

char S[2501];
long long dp[2501][2501], mod=1e9+9, h[2501], mul=998244353, nex[2501][2501];

int main(){
    h[0]=1;
    for(int i=1;i<2501;i++) h[i]=h[i-1]*mul%mod;
    int n;
    long long a, b, c;
    scanf("%d%s%lld%lld%lld", &n, S, &a, &b, &c);
    for(int i=0;i<=n;i++) for(int j=i;j<=n;j++) dp[i][j]=(j-i+1)*a+b;
    for(int l=1;l<=n;l++){
        map<long long, long long> m;
        queue<long long> q[2501];
        long long hc=0, cnt=0;
        for(int i=0;i<l;i++) hc=(hc*mul+(S[i]-'a'))%mod;
        m[hc]=++cnt;
        q[cnt].push(0);
        for(int i=l;i<n;i++){
            hc=(hc*mul-h[l]*(S[i-l]-'a')+(S[i]-'a'))%mod;
            if(m.find(hc)==m.end()) m[hc]=++cnt;
            long long x=m[hc];
            while(!q[x].empty() && q[x].front()+l-1<i-l+1) nex[q[x].front()][q[x].front()+l-1]=i-l-q[x].front()+1, q[x].pop();
            q[x].push(i-l+1);
        }
    }
    for(int l=1;l<=n;l++){
        for(int i=0;i<n-l+1;i++){
            int j=i+l-1, k=0, j1=j, cnt=1;
            if(i) dp[i-1][j]=min(dp[i-1][j], dp[i][j]+a);
            if(j+1!=n) dp[i][j+1]=min(dp[i][j+1], dp[i][j]+a);
            while(nex[i+k][j]){
                int x=nex[i+k][j];
                j+=x; k+=x; cnt++;
                dp[i][j]=min(dp[i][j], dp[i][j1]+(j-i+1-l*cnt)*a+b+c*cnt);
            }
        }
    }
    printf("%lld\n", dp[0][n-1]-b);
    return 0;
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d%s%lld%lld%lld", &n, S, &a, &b, &c);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2004 KB Output is correct
2 Correct 2 ms 2004 KB Output is correct
3 Correct 2 ms 2004 KB Output is correct
4 Correct 2 ms 2004 KB Output is correct
5 Correct 3 ms 2004 KB Output is correct
6 Correct 2 ms 2004 KB Output is correct
7 Correct 3 ms 2004 KB Output is correct
8 Correct 2 ms 2004 KB Output is correct
9 Correct 2 ms 2004 KB Output is correct
10 Correct 1 ms 2004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2004 KB Output is correct
2 Correct 2 ms 2004 KB Output is correct
3 Correct 699 ms 36292 KB Output is correct
4 Correct 782 ms 40828 KB Output is correct
5 Correct 884 ms 45912 KB Output is correct
6 Correct 1059 ms 51512 KB Output is correct
7 Correct 1195 ms 57744 KB Output is correct
8 Correct 1152 ms 57740 KB Output is correct
9 Correct 1199 ms 57860 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 2004 KB Output is correct
12 Correct 2 ms 2004 KB Output is correct
13 Correct 2 ms 2004 KB Output is correct
14 Correct 3 ms 2004 KB Output is correct
15 Correct 3 ms 2004 KB Output is correct
16 Correct 7 ms 2232 KB Output is correct
17 Correct 2 ms 2004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2004 KB Output is correct
2 Correct 2 ms 2004 KB Output is correct
3 Correct 2 ms 2004 KB Output is correct
4 Correct 2 ms 2004 KB Output is correct
5 Correct 3 ms 2004 KB Output is correct
6 Correct 2 ms 2004 KB Output is correct
7 Correct 3 ms 2004 KB Output is correct
8 Correct 2 ms 2004 KB Output is correct
9 Correct 2 ms 2004 KB Output is correct
10 Correct 1 ms 2004 KB Output is correct
11 Correct 3 ms 2004 KB Output is correct
12 Correct 4 ms 2004 KB Output is correct
13 Correct 4 ms 2004 KB Output is correct
14 Correct 2 ms 2000 KB Output is correct
15 Correct 5 ms 2132 KB Output is correct
16 Correct 5 ms 2004 KB Output is correct
17 Correct 2 ms 2004 KB Output is correct
18 Correct 1 ms 2004 KB Output is correct
19 Correct 4 ms 2004 KB Output is correct
20 Correct 2 ms 2004 KB Output is correct
21 Correct 7 ms 2236 KB Output is correct
22 Correct 7 ms 2224 KB Output is correct
23 Correct 7 ms 2132 KB Output is correct
24 Correct 7 ms 2220 KB Output is correct
25 Correct 7 ms 2132 KB Output is correct
26 Correct 7 ms 2132 KB Output is correct
27 Correct 6 ms 2228 KB Output is correct
28 Correct 6 ms 2132 KB Output is correct
29 Correct 6 ms 2132 KB Output is correct
30 Correct 6 ms 2228 KB Output is correct
31 Correct 6 ms 2204 KB Output is correct
32 Correct 7 ms 2132 KB Output is correct
33 Correct 6 ms 2172 KB Output is correct
34 Correct 1 ms 2004 KB Output is correct
35 Correct 2 ms 2004 KB Output is correct
36 Correct 2 ms 2004 KB Output is correct
37 Correct 3 ms 2004 KB Output is correct
38 Correct 5 ms 2004 KB Output is correct
39 Correct 8 ms 2132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2004 KB Output is correct
2 Correct 2 ms 2004 KB Output is correct
3 Correct 2 ms 2004 KB Output is correct
4 Correct 2 ms 2004 KB Output is correct
5 Correct 3 ms 2004 KB Output is correct
6 Correct 2 ms 2004 KB Output is correct
7 Correct 3 ms 2004 KB Output is correct
8 Correct 2 ms 2004 KB Output is correct
9 Correct 2 ms 2004 KB Output is correct
10 Correct 1 ms 2004 KB Output is correct
11 Correct 3 ms 2004 KB Output is correct
12 Correct 4 ms 2004 KB Output is correct
13 Correct 4 ms 2004 KB Output is correct
14 Correct 2 ms 2000 KB Output is correct
15 Correct 5 ms 2132 KB Output is correct
16 Correct 5 ms 2004 KB Output is correct
17 Correct 2 ms 2004 KB Output is correct
18 Correct 1 ms 2004 KB Output is correct
19 Correct 4 ms 2004 KB Output is correct
20 Correct 2 ms 2004 KB Output is correct
21 Correct 7 ms 2236 KB Output is correct
22 Correct 7 ms 2224 KB Output is correct
23 Correct 7 ms 2132 KB Output is correct
24 Correct 7 ms 2220 KB Output is correct
25 Correct 7 ms 2132 KB Output is correct
26 Correct 7 ms 2132 KB Output is correct
27 Correct 6 ms 2228 KB Output is correct
28 Correct 6 ms 2132 KB Output is correct
29 Correct 6 ms 2132 KB Output is correct
30 Correct 6 ms 2228 KB Output is correct
31 Correct 6 ms 2204 KB Output is correct
32 Correct 7 ms 2132 KB Output is correct
33 Correct 6 ms 2172 KB Output is correct
34 Correct 1 ms 2004 KB Output is correct
35 Correct 2 ms 2004 KB Output is correct
36 Correct 2 ms 2004 KB Output is correct
37 Correct 3 ms 2004 KB Output is correct
38 Correct 5 ms 2004 KB Output is correct
39 Correct 8 ms 2132 KB Output is correct
40 Correct 19 ms 2696 KB Output is correct
41 Correct 41 ms 3816 KB Output is correct
42 Correct 47 ms 3772 KB Output is correct
43 Correct 44 ms 3668 KB Output is correct
44 Correct 42 ms 3668 KB Output is correct
45 Correct 48 ms 3668 KB Output is correct
46 Correct 48 ms 3668 KB Output is correct
47 Correct 44 ms 3764 KB Output is correct
48 Correct 56 ms 3668 KB Output is correct
49 Correct 47 ms 3668 KB Output is correct
50 Correct 43 ms 3668 KB Output is correct
51 Correct 40 ms 3792 KB Output is correct
52 Correct 44 ms 3816 KB Output is correct
53 Correct 43 ms 3676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2004 KB Output is correct
2 Correct 2 ms 2004 KB Output is correct
3 Correct 2 ms 2004 KB Output is correct
4 Correct 2 ms 2004 KB Output is correct
5 Correct 3 ms 2004 KB Output is correct
6 Correct 2 ms 2004 KB Output is correct
7 Correct 3 ms 2004 KB Output is correct
8 Correct 2 ms 2004 KB Output is correct
9 Correct 2 ms 2004 KB Output is correct
10 Correct 1 ms 2004 KB Output is correct
11 Correct 3 ms 2004 KB Output is correct
12 Correct 4 ms 2004 KB Output is correct
13 Correct 4 ms 2004 KB Output is correct
14 Correct 2 ms 2000 KB Output is correct
15 Correct 5 ms 2132 KB Output is correct
16 Correct 5 ms 2004 KB Output is correct
17 Correct 2 ms 2004 KB Output is correct
18 Correct 1 ms 2004 KB Output is correct
19 Correct 4 ms 2004 KB Output is correct
20 Correct 2 ms 2004 KB Output is correct
21 Correct 7 ms 2236 KB Output is correct
22 Correct 7 ms 2224 KB Output is correct
23 Correct 7 ms 2132 KB Output is correct
24 Correct 7 ms 2220 KB Output is correct
25 Correct 7 ms 2132 KB Output is correct
26 Correct 7 ms 2132 KB Output is correct
27 Correct 6 ms 2228 KB Output is correct
28 Correct 6 ms 2132 KB Output is correct
29 Correct 6 ms 2132 KB Output is correct
30 Correct 6 ms 2228 KB Output is correct
31 Correct 6 ms 2204 KB Output is correct
32 Correct 7 ms 2132 KB Output is correct
33 Correct 6 ms 2172 KB Output is correct
34 Correct 1 ms 2004 KB Output is correct
35 Correct 2 ms 2004 KB Output is correct
36 Correct 2 ms 2004 KB Output is correct
37 Correct 3 ms 2004 KB Output is correct
38 Correct 5 ms 2004 KB Output is correct
39 Correct 8 ms 2132 KB Output is correct
40 Correct 19 ms 2696 KB Output is correct
41 Correct 41 ms 3816 KB Output is correct
42 Correct 47 ms 3772 KB Output is correct
43 Correct 44 ms 3668 KB Output is correct
44 Correct 42 ms 3668 KB Output is correct
45 Correct 48 ms 3668 KB Output is correct
46 Correct 48 ms 3668 KB Output is correct
47 Correct 44 ms 3764 KB Output is correct
48 Correct 56 ms 3668 KB Output is correct
49 Correct 47 ms 3668 KB Output is correct
50 Correct 43 ms 3668 KB Output is correct
51 Correct 40 ms 3792 KB Output is correct
52 Correct 44 ms 3816 KB Output is correct
53 Correct 43 ms 3676 KB Output is correct
54 Correct 117 ms 6432 KB Output is correct
55 Correct 310 ms 15900 KB Output is correct
56 Correct 336 ms 14076 KB Output is correct
57 Correct 346 ms 14056 KB Output is correct
58 Correct 312 ms 14012 KB Output is correct
59 Correct 356 ms 13968 KB Output is correct
60 Correct 348 ms 14056 KB Output is correct
61 Correct 316 ms 15436 KB Output is correct
62 Correct 313 ms 15884 KB Output is correct
63 Correct 362 ms 14884 KB Output is correct
64 Correct 354 ms 14852 KB Output is correct
65 Correct 324 ms 15604 KB Output is correct
66 Correct 333 ms 15604 KB Output is correct
67 Correct 394 ms 13924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2004 KB Output is correct
2 Correct 2 ms 2004 KB Output is correct
3 Correct 2 ms 2004 KB Output is correct
4 Correct 2 ms 2004 KB Output is correct
5 Correct 3 ms 2004 KB Output is correct
6 Correct 2 ms 2004 KB Output is correct
7 Correct 3 ms 2004 KB Output is correct
8 Correct 2 ms 2004 KB Output is correct
9 Correct 2 ms 2004 KB Output is correct
10 Correct 1 ms 2004 KB Output is correct
11 Correct 3 ms 2004 KB Output is correct
12 Correct 2 ms 2004 KB Output is correct
13 Correct 699 ms 36292 KB Output is correct
14 Correct 782 ms 40828 KB Output is correct
15 Correct 884 ms 45912 KB Output is correct
16 Correct 1059 ms 51512 KB Output is correct
17 Correct 1195 ms 57744 KB Output is correct
18 Correct 1152 ms 57740 KB Output is correct
19 Correct 1199 ms 57860 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 2004 KB Output is correct
22 Correct 2 ms 2004 KB Output is correct
23 Correct 2 ms 2004 KB Output is correct
24 Correct 3 ms 2004 KB Output is correct
25 Correct 3 ms 2004 KB Output is correct
26 Correct 7 ms 2232 KB Output is correct
27 Correct 2 ms 2004 KB Output is correct
28 Correct 3 ms 2004 KB Output is correct
29 Correct 4 ms 2004 KB Output is correct
30 Correct 4 ms 2004 KB Output is correct
31 Correct 2 ms 2000 KB Output is correct
32 Correct 5 ms 2132 KB Output is correct
33 Correct 5 ms 2004 KB Output is correct
34 Correct 2 ms 2004 KB Output is correct
35 Correct 1 ms 2004 KB Output is correct
36 Correct 4 ms 2004 KB Output is correct
37 Correct 2 ms 2004 KB Output is correct
38 Correct 7 ms 2236 KB Output is correct
39 Correct 7 ms 2224 KB Output is correct
40 Correct 7 ms 2132 KB Output is correct
41 Correct 7 ms 2220 KB Output is correct
42 Correct 7 ms 2132 KB Output is correct
43 Correct 7 ms 2132 KB Output is correct
44 Correct 6 ms 2228 KB Output is correct
45 Correct 6 ms 2132 KB Output is correct
46 Correct 6 ms 2132 KB Output is correct
47 Correct 6 ms 2228 KB Output is correct
48 Correct 6 ms 2204 KB Output is correct
49 Correct 7 ms 2132 KB Output is correct
50 Correct 6 ms 2172 KB Output is correct
51 Correct 1 ms 2004 KB Output is correct
52 Correct 2 ms 2004 KB Output is correct
53 Correct 2 ms 2004 KB Output is correct
54 Correct 3 ms 2004 KB Output is correct
55 Correct 5 ms 2004 KB Output is correct
56 Correct 8 ms 2132 KB Output is correct
57 Correct 19 ms 2696 KB Output is correct
58 Correct 41 ms 3816 KB Output is correct
59 Correct 47 ms 3772 KB Output is correct
60 Correct 44 ms 3668 KB Output is correct
61 Correct 42 ms 3668 KB Output is correct
62 Correct 48 ms 3668 KB Output is correct
63 Correct 48 ms 3668 KB Output is correct
64 Correct 44 ms 3764 KB Output is correct
65 Correct 56 ms 3668 KB Output is correct
66 Correct 47 ms 3668 KB Output is correct
67 Correct 43 ms 3668 KB Output is correct
68 Correct 40 ms 3792 KB Output is correct
69 Correct 44 ms 3816 KB Output is correct
70 Correct 43 ms 3676 KB Output is correct
71 Correct 117 ms 6432 KB Output is correct
72 Correct 310 ms 15900 KB Output is correct
73 Correct 336 ms 14076 KB Output is correct
74 Correct 346 ms 14056 KB Output is correct
75 Correct 312 ms 14012 KB Output is correct
76 Correct 356 ms 13968 KB Output is correct
77 Correct 348 ms 14056 KB Output is correct
78 Correct 316 ms 15436 KB Output is correct
79 Correct 313 ms 15884 KB Output is correct
80 Correct 362 ms 14884 KB Output is correct
81 Correct 354 ms 14852 KB Output is correct
82 Correct 324 ms 15604 KB Output is correct
83 Correct 333 ms 15604 KB Output is correct
84 Correct 394 ms 13924 KB Output is correct
85 Correct 727 ms 24724 KB Output is correct
86 Correct 1511 ms 45880 KB Output is correct
87 Correct 1498 ms 45796 KB Output is correct
88 Correct 1499 ms 45732 KB Output is correct
89 Correct 1593 ms 45676 KB Output is correct
90 Correct 1472 ms 45620 KB Output is correct
91 Correct 1091 ms 57360 KB Output is correct
92 Correct 1074 ms 57644 KB Output is correct
93 Correct 1422 ms 52980 KB Output is correct
94 Correct 1449 ms 51600 KB Output is correct
95 Correct 1443 ms 56344 KB Output is correct
96 Correct 1427 ms 56232 KB Output is correct
97 Incorrect 1493 ms 45620 KB Output isn't correct
98 Halted 0 ms 0 KB -