Submission #711206

# Submission time Handle Problem Language Result Execution time Memory
711206 2023-03-16T09:53:14 Z konstantys Copy and Paste 3 (JOI22_copypaste3) C++14
100 / 100
374 ms 34036 KB
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<map>
#define duzo 1000000000000000LL
using namespace std;
map<long long,int> mp;
string s;
int n,m;
long long a,b,c,dp[2501][2501],k,l;
long long st,st2;
short lst[30],kol[2501],kol2[2501],kol3[2501][30],przed[2501];
int main(){
  ios_base::sync_with_stdio(0);
  //cerr<<modpow(base,MOD2-2,MOD2);
  cin>>n;
  cin>>s;
  cin>>a>>b>>c;
  st=1;
  st2=1;
  for(int i=n-1;i>=0;i--){
    dp[i][i]=a-duzo;
    kol[i]=n-lst[((char)s[i])-'a'];
    kol2[i]=kol[i];
    lst[((char)s[i])-'a']=n-i;
  }
  kol2[n]=n;
  kol[n]=n;
  for(int i=1;i<n;i++){
    //cerr<<kol[0]<<"\n";
    //cout<<dp[0][n-1]+duzo<<"???\n";
    for(int u=0;u<n-i;u++){
      dp[u][u+i]=min(dp[u][u+i],a+min(dp[u][u+i-1],dp[u+1][u+i]));
    }
    //cerr<<dp[0][n-1]+duzo<<"!!!\n";
    for(int u=0;u<=n-i;u++){
      if(kol[u]==n) continue;
      //if(u==1) cerr<<i<<" "<<u<<" "<<kol[u]<<"\n";
      m=kol[u];
      l=m-(u+i);
      k=dp[u][u+i-1];
      k+=b+c;
      while(m!=n){
        k+=c;
        dp[u][m+i-1]=min(dp[u][m+i-1],k+l*a);
        //if(dp[0][n-1]+duzo==363) cerr<<u<<" "<<u+i-1<<"!!!";
        //cerr<<k+duzo<<" "<<l*a<<"  "<<m<<" "<<kol[m]<<"  "<<i<<"\n";
        l+=kol[m]-m-i;
        m=kol[m];
      }
    }
    for(int u=n-i-1;u>=0;u--){
      if(kol2[u]+i<n)
        for(int j=0;j<26;j++) kol3[u][j]=kol3[kol2[u]][j];
      else
        for(int j=0;j<26;j++) kol3[u][j]=n;
      kol2[u]=kol3[u][((char)s[u+i]-'a')];
      kol3[u][((char)s[u+i]-'a')]=u;
      przed[kol2[u]]=-u-2;
      //cerr<<przed[u]<<" "<<kol2[u]<<"- ";
      //cerr<<kol2[u];
    }
    //cerr<<"\n";
    kol2[n-i]=n;
    kol[n-i]=n;
    for(int u=0;u<n-i;u++){
      //cerr<<przed[u]<<" "<<kol2[u]<<", ";
      if(przed[u]<-1) przed[u]=-przed[u]-2; else przed[u]=-1;
      if(przed[u]==-1)
        kol[u]=u;
      else
        kol[u]=kol[przed[u]];
      //cerr<<kol2[0]<<"\n";
      while(kol[u]<=u+i) kol[u]=kol2[kol[u]];
    }
    //cerr<<"\n";
    //cerr<<"AA";
  }
  cout<<dp[0][n-1]+duzo;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 184 ms 20852 KB Output is correct
4 Correct 202 ms 23780 KB Output is correct
5 Correct 253 ms 26844 KB Output is correct
6 Correct 282 ms 30248 KB Output is correct
7 Correct 369 ms 33948 KB Output is correct
8 Correct 374 ms 33868 KB Output is correct
9 Correct 341 ms 33940 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 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 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 356 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 452 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 456 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 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 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 356 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 452 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 456 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 456 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
41 Correct 3 ms 1236 KB Output is correct
42 Correct 1 ms 1220 KB Output is correct
43 Correct 2 ms 1224 KB Output is correct
44 Correct 1 ms 1224 KB Output is correct
45 Correct 2 ms 1220 KB Output is correct
46 Correct 1 ms 1224 KB Output is correct
47 Correct 2 ms 1228 KB Output is correct
48 Correct 2 ms 1236 KB Output is correct
49 Correct 2 ms 1236 KB Output is correct
50 Correct 2 ms 1236 KB Output is correct
51 Correct 2 ms 1236 KB Output is correct
52 Correct 2 ms 1224 KB Output is correct
53 Correct 1 ms 1224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 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 324 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 356 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 452 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 456 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 456 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
41 Correct 3 ms 1236 KB Output is correct
42 Correct 1 ms 1220 KB Output is correct
43 Correct 2 ms 1224 KB Output is correct
44 Correct 1 ms 1224 KB Output is correct
45 Correct 2 ms 1220 KB Output is correct
46 Correct 1 ms 1224 KB Output is correct
47 Correct 2 ms 1228 KB Output is correct
48 Correct 2 ms 1236 KB Output is correct
49 Correct 2 ms 1236 KB Output is correct
50 Correct 2 ms 1236 KB Output is correct
51 Correct 2 ms 1236 KB Output is correct
52 Correct 2 ms 1224 KB Output is correct
53 Correct 1 ms 1224 KB Output is correct
54 Correct 3 ms 2900 KB Output is correct
55 Correct 36 ms 8336 KB Output is correct
56 Correct 20 ms 8276 KB Output is correct
57 Correct 16 ms 8320 KB Output is correct
58 Correct 14 ms 8304 KB Output is correct
59 Correct 18 ms 8276 KB Output is correct
60 Correct 13 ms 8216 KB Output is correct
61 Correct 20 ms 8276 KB Output is correct
62 Correct 36 ms 8276 KB Output is correct
63 Correct 16 ms 8276 KB Output is correct
64 Correct 17 ms 8276 KB Output is correct
65 Correct 23 ms 8260 KB Output is correct
66 Correct 23 ms 8268 KB Output is correct
67 Correct 14 ms 8340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 184 ms 20852 KB Output is correct
14 Correct 202 ms 23780 KB Output is correct
15 Correct 253 ms 26844 KB Output is correct
16 Correct 282 ms 30248 KB Output is correct
17 Correct 369 ms 33948 KB Output is correct
18 Correct 374 ms 33868 KB Output is correct
19 Correct 341 ms 33940 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 332 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 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 324 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 324 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 356 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 452 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 1 ms 468 KB Output is correct
50 Correct 1 ms 456 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 0 ms 340 KB Output is correct
56 Correct 1 ms 456 KB Output is correct
57 Correct 1 ms 596 KB Output is correct
58 Correct 3 ms 1236 KB Output is correct
59 Correct 1 ms 1220 KB Output is correct
60 Correct 2 ms 1224 KB Output is correct
61 Correct 1 ms 1224 KB Output is correct
62 Correct 2 ms 1220 KB Output is correct
63 Correct 1 ms 1224 KB Output is correct
64 Correct 2 ms 1228 KB Output is correct
65 Correct 2 ms 1236 KB Output is correct
66 Correct 2 ms 1236 KB Output is correct
67 Correct 2 ms 1236 KB Output is correct
68 Correct 2 ms 1236 KB Output is correct
69 Correct 2 ms 1224 KB Output is correct
70 Correct 1 ms 1224 KB Output is correct
71 Correct 3 ms 2900 KB Output is correct
72 Correct 36 ms 8336 KB Output is correct
73 Correct 20 ms 8276 KB Output is correct
74 Correct 16 ms 8320 KB Output is correct
75 Correct 14 ms 8304 KB Output is correct
76 Correct 18 ms 8276 KB Output is correct
77 Correct 13 ms 8216 KB Output is correct
78 Correct 20 ms 8276 KB Output is correct
79 Correct 36 ms 8276 KB Output is correct
80 Correct 16 ms 8276 KB Output is correct
81 Correct 17 ms 8276 KB Output is correct
82 Correct 23 ms 8260 KB Output is correct
83 Correct 23 ms 8268 KB Output is correct
84 Correct 14 ms 8340 KB Output is correct
85 Correct 44 ms 16468 KB Output is correct
86 Correct 104 ms 33940 KB Output is correct
87 Correct 95 ms 33924 KB Output is correct
88 Correct 89 ms 33920 KB Output is correct
89 Correct 82 ms 33892 KB Output is correct
90 Correct 80 ms 33824 KB Output is correct
91 Correct 229 ms 33896 KB Output is correct
92 Correct 263 ms 33940 KB Output is correct
93 Correct 112 ms 33928 KB Output is correct
94 Correct 127 ms 33916 KB Output is correct
95 Correct 207 ms 34004 KB Output is correct
96 Correct 206 ms 34036 KB Output is correct
97 Correct 80 ms 33868 KB Output is correct