# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
550554 | 2022-04-18T13:28:59 Z | fcmalkcin | Copy and Paste 3 (JOI22_copypaste3) | C++17 | 709 ms | 629576 KB |
#include<bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define ff first #define ss second #define endl "\n" #define pb push_back #define F(i,a,b) for(ll i=a;i<=b;i++) const ll maxn=2e3+530; const ll base=3e18; const ll mod= 1e9+7 ; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); /// have medal in APIO /// goal 2/8 ll n, a, b, c; string s; ll dp[maxn][maxn]; vector<int> gr[maxn*maxn]; ll cnt=0; int nxt[maxn*maxn][27]; vector<int> adj[maxn]; void add(string s,ll l) { ll nw=0; ll dep=0; for (auto to:s) { dep++; ll h=(to-'a'+1); if (!nxt[nw][h]) { cnt++; nxt[nw][h]=cnt; adj[dep].pb(nxt[nw][h]); } nw=nxt[nw][h]; gr[nw].pb(l); } } ll rt[maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("t.inp","r")) { freopen("test.inp","r",stdin); freopen("test.out","w",stdout); } cin>> n>> s>> a>> b>> c; s=" "+s; for (int i=1;i<=n;i++) { string t=s.substr(i,n-i+1); add(t,i); } for (int i=1;i<=n;i++) { for (int j=i;j<=n;j++) { dp[i][j]=a*(j-i+1); } } for (int len=1;len<=n;len++) { for (auto nw:adj[len]) { vector<int> vt=gr[nw]; ll pre=vt.size(); for (int i=vt.size()-1;i>=0;i--) { while (vt[pre-1]-len+1>vt[i]) pre--; rt[i]=pre; } for (int i=0;i<vt.size();i++) { ll nw=rt[i]; ll cnt=1; while (nw<vt.size()) { ll l=vt[i]; ll r=vt[nw]+len-1; cnt++; dp[l][r]=min(dp[l][r],(r-l+1-cnt*len)*a+b+dp[l][l+len-1]+c*cnt); /* if (len==1&&vt[0]==3&&i==0) { cout <<" chk1"<<endl; cout <<l<<" "<<r<<" "<<dp[l][r]<<" "<<dp[l][l+len-1]<<" "<<b*cnt<<" "<<c<<" chk1"<<endl; }*/ nw=rt[nw]; } } } for (int i=1;i+len-1<=n;i++) { ll j=i+len-1; dp[i][j+1]=min(dp[i][j+1],dp[i][j]+a); dp[i-1][j]=min(dp[i-1][j],dp[i][j]+a); } } cout <<dp[1][n]<<endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 66 ms | 150604 KB | Output is correct |
2 | Correct | 76 ms | 150716 KB | Output is correct |
3 | Correct | 77 ms | 150708 KB | Output is correct |
4 | Correct | 70 ms | 150700 KB | Output is correct |
5 | Correct | 72 ms | 150656 KB | Output is correct |
6 | Correct | 72 ms | 150708 KB | Output is correct |
7 | Correct | 69 ms | 150604 KB | Output is correct |
8 | Correct | 74 ms | 150604 KB | Output is correct |
9 | Correct | 74 ms | 150644 KB | Output is correct |
10 | Correct | 70 ms | 150604 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 73 ms | 150748 KB | Output is correct |
2 | Correct | 70 ms | 150692 KB | Output is correct |
3 | Correct | 246 ms | 180772 KB | Output is correct |
4 | Correct | 241 ms | 184780 KB | Output is correct |
5 | Correct | 280 ms | 189896 KB | Output is correct |
6 | Correct | 330 ms | 195772 KB | Output is correct |
7 | Correct | 364 ms | 202676 KB | Output is correct |
8 | Correct | 365 ms | 202644 KB | Output is correct |
9 | Correct | 406 ms | 202704 KB | Output is correct |
10 | Correct | 72 ms | 150680 KB | Output is correct |
11 | Correct | 71 ms | 150680 KB | Output is correct |
12 | Correct | 71 ms | 150640 KB | Output is correct |
13 | Correct | 70 ms | 150688 KB | Output is correct |
14 | Correct | 80 ms | 150708 KB | Output is correct |
15 | Correct | 76 ms | 150660 KB | Output is correct |
16 | Correct | 68 ms | 150728 KB | Output is correct |
17 | Correct | 72 ms | 150712 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 66 ms | 150604 KB | Output is correct |
2 | Correct | 76 ms | 150716 KB | Output is correct |
3 | Correct | 77 ms | 150708 KB | Output is correct |
4 | Correct | 70 ms | 150700 KB | Output is correct |
5 | Correct | 72 ms | 150656 KB | Output is correct |
6 | Correct | 72 ms | 150708 KB | Output is correct |
7 | Correct | 69 ms | 150604 KB | Output is correct |
8 | Correct | 74 ms | 150604 KB | Output is correct |
9 | Correct | 74 ms | 150644 KB | Output is correct |
10 | Correct | 70 ms | 150604 KB | Output is correct |
11 | Correct | 71 ms | 150700 KB | Output is correct |
12 | Correct | 73 ms | 150724 KB | Output is correct |
13 | Correct | 76 ms | 150732 KB | Output is correct |
14 | Correct | 70 ms | 150736 KB | Output is correct |
15 | Correct | 69 ms | 150800 KB | Output is correct |
16 | Correct | 75 ms | 150704 KB | Output is correct |
17 | Correct | 80 ms | 150620 KB | Output is correct |
18 | Correct | 75 ms | 150604 KB | Output is correct |
19 | Correct | 75 ms | 150788 KB | Output is correct |
20 | Correct | 72 ms | 150652 KB | Output is correct |
21 | Correct | 73 ms | 150800 KB | Output is correct |
22 | Correct | 73 ms | 150860 KB | Output is correct |
23 | Correct | 74 ms | 150880 KB | Output is correct |
24 | Correct | 74 ms | 150820 KB | Output is correct |
25 | Correct | 72 ms | 150860 KB | Output is correct |
26 | Correct | 73 ms | 150896 KB | Output is correct |
27 | Correct | 84 ms | 150816 KB | Output is correct |
28 | Correct | 76 ms | 150812 KB | Output is correct |
29 | Correct | 73 ms | 150860 KB | Output is correct |
30 | Correct | 71 ms | 150836 KB | Output is correct |
31 | Correct | 72 ms | 150860 KB | Output is correct |
32 | Correct | 72 ms | 150808 KB | Output is correct |
33 | Correct | 78 ms | 150896 KB | Output is correct |
34 | Correct | 69 ms | 150624 KB | Output is correct |
35 | Correct | 72 ms | 150616 KB | Output is correct |
36 | Correct | 72 ms | 150704 KB | Output is correct |
37 | Correct | 72 ms | 150620 KB | Output is correct |
38 | Correct | 73 ms | 150744 KB | Output is correct |
39 | Correct | 70 ms | 150832 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 66 ms | 150604 KB | Output is correct |
2 | Correct | 76 ms | 150716 KB | Output is correct |
3 | Correct | 77 ms | 150708 KB | Output is correct |
4 | Correct | 70 ms | 150700 KB | Output is correct |
5 | Correct | 72 ms | 150656 KB | Output is correct |
6 | Correct | 72 ms | 150708 KB | Output is correct |
7 | Correct | 69 ms | 150604 KB | Output is correct |
8 | Correct | 74 ms | 150604 KB | Output is correct |
9 | Correct | 74 ms | 150644 KB | Output is correct |
10 | Correct | 70 ms | 150604 KB | Output is correct |
11 | Correct | 71 ms | 150700 KB | Output is correct |
12 | Correct | 73 ms | 150724 KB | Output is correct |
13 | Correct | 76 ms | 150732 KB | Output is correct |
14 | Correct | 70 ms | 150736 KB | Output is correct |
15 | Correct | 69 ms | 150800 KB | Output is correct |
16 | Correct | 75 ms | 150704 KB | Output is correct |
17 | Correct | 80 ms | 150620 KB | Output is correct |
18 | Correct | 75 ms | 150604 KB | Output is correct |
19 | Correct | 75 ms | 150788 KB | Output is correct |
20 | Correct | 72 ms | 150652 KB | Output is correct |
21 | Correct | 73 ms | 150800 KB | Output is correct |
22 | Correct | 73 ms | 150860 KB | Output is correct |
23 | Correct | 74 ms | 150880 KB | Output is correct |
24 | Correct | 74 ms | 150820 KB | Output is correct |
25 | Correct | 72 ms | 150860 KB | Output is correct |
26 | Correct | 73 ms | 150896 KB | Output is correct |
27 | Correct | 84 ms | 150816 KB | Output is correct |
28 | Correct | 76 ms | 150812 KB | Output is correct |
29 | Correct | 73 ms | 150860 KB | Output is correct |
30 | Correct | 71 ms | 150836 KB | Output is correct |
31 | Correct | 72 ms | 150860 KB | Output is correct |
32 | Correct | 72 ms | 150808 KB | Output is correct |
33 | Correct | 78 ms | 150896 KB | Output is correct |
34 | Correct | 69 ms | 150624 KB | Output is correct |
35 | Correct | 72 ms | 150616 KB | Output is correct |
36 | Correct | 72 ms | 150704 KB | Output is correct |
37 | Correct | 72 ms | 150620 KB | Output is correct |
38 | Correct | 73 ms | 150744 KB | Output is correct |
39 | Correct | 70 ms | 150832 KB | Output is correct |
40 | Correct | 72 ms | 151456 KB | Output is correct |
41 | Correct | 83 ms | 151736 KB | Output is correct |
42 | Correct | 78 ms | 154336 KB | Output is correct |
43 | Correct | 87 ms | 154548 KB | Output is correct |
44 | Correct | 75 ms | 154496 KB | Output is correct |
45 | Correct | 74 ms | 154496 KB | Output is correct |
46 | Correct | 74 ms | 154420 KB | Output is correct |
47 | Correct | 85 ms | 152304 KB | Output is correct |
48 | Correct | 85 ms | 153376 KB | Output is correct |
49 | Correct | 73 ms | 153708 KB | Output is correct |
50 | Correct | 74 ms | 153812 KB | Output is correct |
51 | Correct | 72 ms | 153164 KB | Output is correct |
52 | Correct | 80 ms | 153192 KB | Output is correct |
53 | Correct | 76 ms | 154496 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 66 ms | 150604 KB | Output is correct |
2 | Correct | 76 ms | 150716 KB | Output is correct |
3 | Correct | 77 ms | 150708 KB | Output is correct |
4 | Correct | 70 ms | 150700 KB | Output is correct |
5 | Correct | 72 ms | 150656 KB | Output is correct |
6 | Correct | 72 ms | 150708 KB | Output is correct |
7 | Correct | 69 ms | 150604 KB | Output is correct |
8 | Correct | 74 ms | 150604 KB | Output is correct |
9 | Correct | 74 ms | 150644 KB | Output is correct |
10 | Correct | 70 ms | 150604 KB | Output is correct |
11 | Correct | 71 ms | 150700 KB | Output is correct |
12 | Correct | 73 ms | 150724 KB | Output is correct |
13 | Correct | 76 ms | 150732 KB | Output is correct |
14 | Correct | 70 ms | 150736 KB | Output is correct |
15 | Correct | 69 ms | 150800 KB | Output is correct |
16 | Correct | 75 ms | 150704 KB | Output is correct |
17 | Correct | 80 ms | 150620 KB | Output is correct |
18 | Correct | 75 ms | 150604 KB | Output is correct |
19 | Correct | 75 ms | 150788 KB | Output is correct |
20 | Correct | 72 ms | 150652 KB | Output is correct |
21 | Correct | 73 ms | 150800 KB | Output is correct |
22 | Correct | 73 ms | 150860 KB | Output is correct |
23 | Correct | 74 ms | 150880 KB | Output is correct |
24 | Correct | 74 ms | 150820 KB | Output is correct |
25 | Correct | 72 ms | 150860 KB | Output is correct |
26 | Correct | 73 ms | 150896 KB | Output is correct |
27 | Correct | 84 ms | 150816 KB | Output is correct |
28 | Correct | 76 ms | 150812 KB | Output is correct |
29 | Correct | 73 ms | 150860 KB | Output is correct |
30 | Correct | 71 ms | 150836 KB | Output is correct |
31 | Correct | 72 ms | 150860 KB | Output is correct |
32 | Correct | 72 ms | 150808 KB | Output is correct |
33 | Correct | 78 ms | 150896 KB | Output is correct |
34 | Correct | 69 ms | 150624 KB | Output is correct |
35 | Correct | 72 ms | 150616 KB | Output is correct |
36 | Correct | 72 ms | 150704 KB | Output is correct |
37 | Correct | 72 ms | 150620 KB | Output is correct |
38 | Correct | 73 ms | 150744 KB | Output is correct |
39 | Correct | 70 ms | 150832 KB | Output is correct |
40 | Correct | 72 ms | 151456 KB | Output is correct |
41 | Correct | 83 ms | 151736 KB | Output is correct |
42 | Correct | 78 ms | 154336 KB | Output is correct |
43 | Correct | 87 ms | 154548 KB | Output is correct |
44 | Correct | 75 ms | 154496 KB | Output is correct |
45 | Correct | 74 ms | 154496 KB | Output is correct |
46 | Correct | 74 ms | 154420 KB | Output is correct |
47 | Correct | 85 ms | 152304 KB | Output is correct |
48 | Correct | 85 ms | 153376 KB | Output is correct |
49 | Correct | 73 ms | 153708 KB | Output is correct |
50 | Correct | 74 ms | 153812 KB | Output is correct |
51 | Correct | 72 ms | 153164 KB | Output is correct |
52 | Correct | 80 ms | 153192 KB | Output is correct |
53 | Correct | 76 ms | 154496 KB | Output is correct |
54 | Correct | 86 ms | 167068 KB | Output is correct |
55 | Correct | 107 ms | 161476 KB | Output is correct |
56 | Correct | 171 ms | 228816 KB | Output is correct |
57 | Correct | 161 ms | 229256 KB | Output is correct |
58 | Correct | 163 ms | 229456 KB | Output is correct |
59 | Correct | 169 ms | 229692 KB | Output is correct |
60 | Correct | 159 ms | 229736 KB | Output is correct |
61 | Correct | 126 ms | 188936 KB | Output is correct |
62 | Correct | 102 ms | 162012 KB | Output is correct |
63 | Correct | 153 ms | 212320 KB | Output is correct |
64 | Correct | 145 ms | 213028 KB | Output is correct |
65 | Correct | 148 ms | 193992 KB | Output is correct |
66 | Correct | 154 ms | 193956 KB | Output is correct |
67 | Correct | 165 ms | 229896 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 66 ms | 150604 KB | Output is correct |
2 | Correct | 76 ms | 150716 KB | Output is correct |
3 | Correct | 77 ms | 150708 KB | Output is correct |
4 | Correct | 70 ms | 150700 KB | Output is correct |
5 | Correct | 72 ms | 150656 KB | Output is correct |
6 | Correct | 72 ms | 150708 KB | Output is correct |
7 | Correct | 69 ms | 150604 KB | Output is correct |
8 | Correct | 74 ms | 150604 KB | Output is correct |
9 | Correct | 74 ms | 150644 KB | Output is correct |
10 | Correct | 70 ms | 150604 KB | Output is correct |
11 | Correct | 73 ms | 150748 KB | Output is correct |
12 | Correct | 70 ms | 150692 KB | Output is correct |
13 | Correct | 246 ms | 180772 KB | Output is correct |
14 | Correct | 241 ms | 184780 KB | Output is correct |
15 | Correct | 280 ms | 189896 KB | Output is correct |
16 | Correct | 330 ms | 195772 KB | Output is correct |
17 | Correct | 364 ms | 202676 KB | Output is correct |
18 | Correct | 365 ms | 202644 KB | Output is correct |
19 | Correct | 406 ms | 202704 KB | Output is correct |
20 | Correct | 72 ms | 150680 KB | Output is correct |
21 | Correct | 71 ms | 150680 KB | Output is correct |
22 | Correct | 71 ms | 150640 KB | Output is correct |
23 | Correct | 70 ms | 150688 KB | Output is correct |
24 | Correct | 80 ms | 150708 KB | Output is correct |
25 | Correct | 76 ms | 150660 KB | Output is correct |
26 | Correct | 68 ms | 150728 KB | Output is correct |
27 | Correct | 72 ms | 150712 KB | Output is correct |
28 | Correct | 71 ms | 150700 KB | Output is correct |
29 | Correct | 73 ms | 150724 KB | Output is correct |
30 | Correct | 76 ms | 150732 KB | Output is correct |
31 | Correct | 70 ms | 150736 KB | Output is correct |
32 | Correct | 69 ms | 150800 KB | Output is correct |
33 | Correct | 75 ms | 150704 KB | Output is correct |
34 | Correct | 80 ms | 150620 KB | Output is correct |
35 | Correct | 75 ms | 150604 KB | Output is correct |
36 | Correct | 75 ms | 150788 KB | Output is correct |
37 | Correct | 72 ms | 150652 KB | Output is correct |
38 | Correct | 73 ms | 150800 KB | Output is correct |
39 | Correct | 73 ms | 150860 KB | Output is correct |
40 | Correct | 74 ms | 150880 KB | Output is correct |
41 | Correct | 74 ms | 150820 KB | Output is correct |
42 | Correct | 72 ms | 150860 KB | Output is correct |
43 | Correct | 73 ms | 150896 KB | Output is correct |
44 | Correct | 84 ms | 150816 KB | Output is correct |
45 | Correct | 76 ms | 150812 KB | Output is correct |
46 | Correct | 73 ms | 150860 KB | Output is correct |
47 | Correct | 71 ms | 150836 KB | Output is correct |
48 | Correct | 72 ms | 150860 KB | Output is correct |
49 | Correct | 72 ms | 150808 KB | Output is correct |
50 | Correct | 78 ms | 150896 KB | Output is correct |
51 | Correct | 69 ms | 150624 KB | Output is correct |
52 | Correct | 72 ms | 150616 KB | Output is correct |
53 | Correct | 72 ms | 150704 KB | Output is correct |
54 | Correct | 72 ms | 150620 KB | Output is correct |
55 | Correct | 73 ms | 150744 KB | Output is correct |
56 | Correct | 70 ms | 150832 KB | Output is correct |
57 | Correct | 72 ms | 151456 KB | Output is correct |
58 | Correct | 83 ms | 151736 KB | Output is correct |
59 | Correct | 78 ms | 154336 KB | Output is correct |
60 | Correct | 87 ms | 154548 KB | Output is correct |
61 | Correct | 75 ms | 154496 KB | Output is correct |
62 | Correct | 74 ms | 154496 KB | Output is correct |
63 | Correct | 74 ms | 154420 KB | Output is correct |
64 | Correct | 85 ms | 152304 KB | Output is correct |
65 | Correct | 85 ms | 153376 KB | Output is correct |
66 | Correct | 73 ms | 153708 KB | Output is correct |
67 | Correct | 74 ms | 153812 KB | Output is correct |
68 | Correct | 72 ms | 153164 KB | Output is correct |
69 | Correct | 80 ms | 153192 KB | Output is correct |
70 | Correct | 76 ms | 154496 KB | Output is correct |
71 | Correct | 86 ms | 167068 KB | Output is correct |
72 | Correct | 107 ms | 161476 KB | Output is correct |
73 | Correct | 171 ms | 228816 KB | Output is correct |
74 | Correct | 161 ms | 229256 KB | Output is correct |
75 | Correct | 163 ms | 229456 KB | Output is correct |
76 | Correct | 169 ms | 229692 KB | Output is correct |
77 | Correct | 159 ms | 229736 KB | Output is correct |
78 | Correct | 126 ms | 188936 KB | Output is correct |
79 | Correct | 102 ms | 162012 KB | Output is correct |
80 | Correct | 153 ms | 212320 KB | Output is correct |
81 | Correct | 145 ms | 213028 KB | Output is correct |
82 | Correct | 148 ms | 193992 KB | Output is correct |
83 | Correct | 154 ms | 193956 KB | Output is correct |
84 | Correct | 165 ms | 229896 KB | Output is correct |
85 | Correct | 321 ms | 343484 KB | Output is correct |
86 | Correct | 704 ms | 626628 KB | Output is correct |
87 | Correct | 696 ms | 627976 KB | Output is correct |
88 | Correct | 706 ms | 629100 KB | Output is correct |
89 | Correct | 674 ms | 629440 KB | Output is correct |
90 | Correct | 686 ms | 629576 KB | Output is correct |
91 | Correct | 328 ms | 222156 KB | Output is correct |
92 | Correct | 333 ms | 206808 KB | Output is correct |
93 | Correct | 599 ms | 494980 KB | Output is correct |
94 | Correct | 629 ms | 521896 KB | Output is correct |
95 | Correct | 564 ms | 401248 KB | Output is correct |
96 | Correct | 584 ms | 401356 KB | Output is correct |
97 | Correct | 709 ms | 629344 KB | Output is correct |