답안 #714421

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
714421 2023-03-24T10:52:00 Z 089487 Copy and Paste 3 (JOI22_copypaste3) C++14
62 / 100
3000 ms 500416 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include<bits/stdc++.h>
#define int long long
#define quick ios::sync_with_stdio(0);cin.tie(0);
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define repd(x,a,b) for(int x=a;x>=b;x--)
#define lowbit(x) (x&-x)
#define sz(x) (int)(x.size())
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define mp make_pair
#define eb emplace_back
using namespace std;
typedef pair<int,int> pii;
void debug(){
    cout<<"\n";
}
template <class T,class ... U >
void debug(T a, U ... b){
    cout<<a<<" ",debug(b...);
}
const int N=25e2+7;
const int INF=1e18;
const int p=29;
const int Mod=462'779'347'772'851;
int pref[N][N];
int dp[N][N];
string s;
const int M=1e7;
vector<int> v[M];
void build(int n){
	rep(i,1,n){
		rep(j,i,n){
			pref[i][j]=pref[i][j-1]*p%Mod+s[j-1]-'a'+2;
			if(pref[i][j]>=Mod) pref[i][j]-=Mod;
		}
	}
}
int nxt[N];
bool vis[M];
signed main(){
	quick
 
	int n;
	cin>>n;
	cin>>s;
	build(n);
	int a,b,c;
	cin>>a>>b>>c;
	map<int,int > mx;
	int cnt=1;
	rep(i,1,n){
		rep(j,i,n){
			dp[i][j]=(j-i+1)*a;
			if(!mx[pref[i][j]]) mx[pref[i][j]]=cnt++;
			v[mx[pref[i][j]]].eb(i);
		}
	}
	rep(L,1,n){
		fill(nxt,nxt+n+1,-1);
		rep(l,1,n-L+1){
			int r=l+L-1;
			int qx=mx[pref[l][r]];
			int n2=sz(v[qx]);
			if(l<r) dp[l][r]=min({dp[l][r],dp[l][r-1]+a,dp[l+1][r]+a});
			if(!vis[qx]&&n2!=1){
				auto _r=v[qx].begin();
				auto E=v[qx].end();
				for(auto i=v[qx].begin();i!=E;++i){
					while(_r!=E&&(*_r)<=(*i)+L-1) _r++;
					nxt[*i]=(_r==E ? -1 : *_r);
				}
				vis[qx]=true;
			}
			int px=nxt[l];
			int pst=1;
			while(px!=-1){
				dp[l][px+L-1]=min(dp[l][px+L-1],(px-l-pst*L)*a+pst*c+b+c+dp[l][r]);
				pst++;
				px=nxt[px];
			}
		}
	}
	cout<<dp[1][n]<<"\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 235300 KB Output is correct
2 Correct 122 ms 235100 KB Output is correct
3 Correct 124 ms 235128 KB Output is correct
4 Correct 123 ms 235180 KB Output is correct
5 Correct 123 ms 235080 KB Output is correct
6 Correct 130 ms 235164 KB Output is correct
7 Correct 124 ms 235124 KB Output is correct
8 Correct 123 ms 235084 KB Output is correct
9 Correct 121 ms 235184 KB Output is correct
10 Correct 122 ms 235128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 235276 KB Output is correct
2 Correct 124 ms 235168 KB Output is correct
3 Correct 477 ms 294136 KB Output is correct
4 Correct 526 ms 301932 KB Output is correct
5 Correct 604 ms 311900 KB Output is correct
6 Correct 756 ms 323784 KB Output is correct
7 Correct 807 ms 335856 KB Output is correct
8 Correct 827 ms 335808 KB Output is correct
9 Correct 816 ms 335828 KB Output is correct
10 Correct 123 ms 235160 KB Output is correct
11 Correct 122 ms 235124 KB Output is correct
12 Correct 135 ms 235060 KB Output is correct
13 Correct 123 ms 235144 KB Output is correct
14 Correct 124 ms 235220 KB Output is correct
15 Correct 124 ms 235264 KB Output is correct
16 Correct 125 ms 235368 KB Output is correct
17 Correct 123 ms 235068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 235300 KB Output is correct
2 Correct 122 ms 235100 KB Output is correct
3 Correct 124 ms 235128 KB Output is correct
4 Correct 123 ms 235180 KB Output is correct
5 Correct 123 ms 235080 KB Output is correct
6 Correct 130 ms 235164 KB Output is correct
7 Correct 124 ms 235124 KB Output is correct
8 Correct 123 ms 235084 KB Output is correct
9 Correct 121 ms 235184 KB Output is correct
10 Correct 122 ms 235128 KB Output is correct
11 Correct 123 ms 235348 KB Output is correct
12 Correct 123 ms 235316 KB Output is correct
13 Correct 127 ms 235232 KB Output is correct
14 Correct 122 ms 235156 KB Output is correct
15 Correct 121 ms 235248 KB Output is correct
16 Correct 125 ms 235260 KB Output is correct
17 Correct 121 ms 235320 KB Output is correct
18 Correct 124 ms 235212 KB Output is correct
19 Correct 127 ms 235168 KB Output is correct
20 Correct 124 ms 235160 KB Output is correct
21 Correct 123 ms 235392 KB Output is correct
22 Correct 123 ms 235440 KB Output is correct
23 Correct 123 ms 235340 KB Output is correct
24 Correct 124 ms 235364 KB Output is correct
25 Correct 124 ms 235592 KB Output is correct
26 Correct 125 ms 235444 KB Output is correct
27 Correct 121 ms 235340 KB Output is correct
28 Correct 123 ms 235364 KB Output is correct
29 Correct 122 ms 235340 KB Output is correct
30 Correct 126 ms 235336 KB Output is correct
31 Correct 123 ms 235456 KB Output is correct
32 Correct 123 ms 235496 KB Output is correct
33 Correct 123 ms 235340 KB Output is correct
34 Correct 124 ms 235132 KB Output is correct
35 Correct 124 ms 235064 KB Output is correct
36 Correct 125 ms 235120 KB Output is correct
37 Correct 123 ms 235100 KB Output is correct
38 Correct 126 ms 235220 KB Output is correct
39 Correct 123 ms 235292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 235300 KB Output is correct
2 Correct 122 ms 235100 KB Output is correct
3 Correct 124 ms 235128 KB Output is correct
4 Correct 123 ms 235180 KB Output is correct
5 Correct 123 ms 235080 KB Output is correct
6 Correct 130 ms 235164 KB Output is correct
7 Correct 124 ms 235124 KB Output is correct
8 Correct 123 ms 235084 KB Output is correct
9 Correct 121 ms 235184 KB Output is correct
10 Correct 122 ms 235128 KB Output is correct
11 Correct 123 ms 235348 KB Output is correct
12 Correct 123 ms 235316 KB Output is correct
13 Correct 127 ms 235232 KB Output is correct
14 Correct 122 ms 235156 KB Output is correct
15 Correct 121 ms 235248 KB Output is correct
16 Correct 125 ms 235260 KB Output is correct
17 Correct 121 ms 235320 KB Output is correct
18 Correct 124 ms 235212 KB Output is correct
19 Correct 127 ms 235168 KB Output is correct
20 Correct 124 ms 235160 KB Output is correct
21 Correct 123 ms 235392 KB Output is correct
22 Correct 123 ms 235440 KB Output is correct
23 Correct 123 ms 235340 KB Output is correct
24 Correct 124 ms 235364 KB Output is correct
25 Correct 124 ms 235592 KB Output is correct
26 Correct 125 ms 235444 KB Output is correct
27 Correct 121 ms 235340 KB Output is correct
28 Correct 123 ms 235364 KB Output is correct
29 Correct 122 ms 235340 KB Output is correct
30 Correct 126 ms 235336 KB Output is correct
31 Correct 123 ms 235456 KB Output is correct
32 Correct 123 ms 235496 KB Output is correct
33 Correct 123 ms 235340 KB Output is correct
34 Correct 124 ms 235132 KB Output is correct
35 Correct 124 ms 235064 KB Output is correct
36 Correct 125 ms 235120 KB Output is correct
37 Correct 123 ms 235100 KB Output is correct
38 Correct 126 ms 235220 KB Output is correct
39 Correct 123 ms 235292 KB Output is correct
40 Correct 125 ms 236196 KB Output is correct
41 Correct 126 ms 237360 KB Output is correct
42 Correct 137 ms 238796 KB Output is correct
43 Correct 148 ms 238884 KB Output is correct
44 Correct 139 ms 238864 KB Output is correct
45 Correct 145 ms 238924 KB Output is correct
46 Correct 137 ms 238972 KB Output is correct
47 Correct 130 ms 237772 KB Output is correct
48 Correct 134 ms 238376 KB Output is correct
49 Correct 135 ms 238408 KB Output is correct
50 Correct 134 ms 238396 KB Output is correct
51 Correct 131 ms 238144 KB Output is correct
52 Correct 135 ms 238104 KB Output is correct
53 Correct 140 ms 238956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 235300 KB Output is correct
2 Correct 122 ms 235100 KB Output is correct
3 Correct 124 ms 235128 KB Output is correct
4 Correct 123 ms 235180 KB Output is correct
5 Correct 123 ms 235080 KB Output is correct
6 Correct 130 ms 235164 KB Output is correct
7 Correct 124 ms 235124 KB Output is correct
8 Correct 123 ms 235084 KB Output is correct
9 Correct 121 ms 235184 KB Output is correct
10 Correct 122 ms 235128 KB Output is correct
11 Correct 123 ms 235348 KB Output is correct
12 Correct 123 ms 235316 KB Output is correct
13 Correct 127 ms 235232 KB Output is correct
14 Correct 122 ms 235156 KB Output is correct
15 Correct 121 ms 235248 KB Output is correct
16 Correct 125 ms 235260 KB Output is correct
17 Correct 121 ms 235320 KB Output is correct
18 Correct 124 ms 235212 KB Output is correct
19 Correct 127 ms 235168 KB Output is correct
20 Correct 124 ms 235160 KB Output is correct
21 Correct 123 ms 235392 KB Output is correct
22 Correct 123 ms 235440 KB Output is correct
23 Correct 123 ms 235340 KB Output is correct
24 Correct 124 ms 235364 KB Output is correct
25 Correct 124 ms 235592 KB Output is correct
26 Correct 125 ms 235444 KB Output is correct
27 Correct 121 ms 235340 KB Output is correct
28 Correct 123 ms 235364 KB Output is correct
29 Correct 122 ms 235340 KB Output is correct
30 Correct 126 ms 235336 KB Output is correct
31 Correct 123 ms 235456 KB Output is correct
32 Correct 123 ms 235496 KB Output is correct
33 Correct 123 ms 235340 KB Output is correct
34 Correct 124 ms 235132 KB Output is correct
35 Correct 124 ms 235064 KB Output is correct
36 Correct 125 ms 235120 KB Output is correct
37 Correct 123 ms 235100 KB Output is correct
38 Correct 126 ms 235220 KB Output is correct
39 Correct 123 ms 235292 KB Output is correct
40 Correct 125 ms 236196 KB Output is correct
41 Correct 126 ms 237360 KB Output is correct
42 Correct 137 ms 238796 KB Output is correct
43 Correct 148 ms 238884 KB Output is correct
44 Correct 139 ms 238864 KB Output is correct
45 Correct 145 ms 238924 KB Output is correct
46 Correct 137 ms 238972 KB Output is correct
47 Correct 130 ms 237772 KB Output is correct
48 Correct 134 ms 238376 KB Output is correct
49 Correct 135 ms 238408 KB Output is correct
50 Correct 134 ms 238396 KB Output is correct
51 Correct 131 ms 238144 KB Output is correct
52 Correct 135 ms 238104 KB Output is correct
53 Correct 140 ms 238956 KB Output is correct
54 Correct 244 ms 249476 KB Output is correct
55 Correct 200 ms 256460 KB Output is correct
56 Correct 1082 ms 297764 KB Output is correct
57 Correct 1033 ms 298032 KB Output is correct
58 Correct 991 ms 298232 KB Output is correct
59 Correct 1002 ms 298328 KB Output is correct
60 Correct 1030 ms 298492 KB Output is correct
61 Correct 668 ms 275712 KB Output is correct
62 Correct 325 ms 257276 KB Output is correct
63 Correct 860 ms 286900 KB Output is correct
64 Correct 848 ms 287712 KB Output is correct
65 Correct 726 ms 276476 KB Output is correct
66 Correct 745 ms 276492 KB Output is correct
67 Correct 1006 ms 298360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 235300 KB Output is correct
2 Correct 122 ms 235100 KB Output is correct
3 Correct 124 ms 235128 KB Output is correct
4 Correct 123 ms 235180 KB Output is correct
5 Correct 123 ms 235080 KB Output is correct
6 Correct 130 ms 235164 KB Output is correct
7 Correct 124 ms 235124 KB Output is correct
8 Correct 123 ms 235084 KB Output is correct
9 Correct 121 ms 235184 KB Output is correct
10 Correct 122 ms 235128 KB Output is correct
11 Correct 123 ms 235276 KB Output is correct
12 Correct 124 ms 235168 KB Output is correct
13 Correct 477 ms 294136 KB Output is correct
14 Correct 526 ms 301932 KB Output is correct
15 Correct 604 ms 311900 KB Output is correct
16 Correct 756 ms 323784 KB Output is correct
17 Correct 807 ms 335856 KB Output is correct
18 Correct 827 ms 335808 KB Output is correct
19 Correct 816 ms 335828 KB Output is correct
20 Correct 123 ms 235160 KB Output is correct
21 Correct 122 ms 235124 KB Output is correct
22 Correct 135 ms 235060 KB Output is correct
23 Correct 123 ms 235144 KB Output is correct
24 Correct 124 ms 235220 KB Output is correct
25 Correct 124 ms 235264 KB Output is correct
26 Correct 125 ms 235368 KB Output is correct
27 Correct 123 ms 235068 KB Output is correct
28 Correct 123 ms 235348 KB Output is correct
29 Correct 123 ms 235316 KB Output is correct
30 Correct 127 ms 235232 KB Output is correct
31 Correct 122 ms 235156 KB Output is correct
32 Correct 121 ms 235248 KB Output is correct
33 Correct 125 ms 235260 KB Output is correct
34 Correct 121 ms 235320 KB Output is correct
35 Correct 124 ms 235212 KB Output is correct
36 Correct 127 ms 235168 KB Output is correct
37 Correct 124 ms 235160 KB Output is correct
38 Correct 123 ms 235392 KB Output is correct
39 Correct 123 ms 235440 KB Output is correct
40 Correct 123 ms 235340 KB Output is correct
41 Correct 124 ms 235364 KB Output is correct
42 Correct 124 ms 235592 KB Output is correct
43 Correct 125 ms 235444 KB Output is correct
44 Correct 121 ms 235340 KB Output is correct
45 Correct 123 ms 235364 KB Output is correct
46 Correct 122 ms 235340 KB Output is correct
47 Correct 126 ms 235336 KB Output is correct
48 Correct 123 ms 235456 KB Output is correct
49 Correct 123 ms 235496 KB Output is correct
50 Correct 123 ms 235340 KB Output is correct
51 Correct 124 ms 235132 KB Output is correct
52 Correct 124 ms 235064 KB Output is correct
53 Correct 125 ms 235120 KB Output is correct
54 Correct 123 ms 235100 KB Output is correct
55 Correct 126 ms 235220 KB Output is correct
56 Correct 123 ms 235292 KB Output is correct
57 Correct 125 ms 236196 KB Output is correct
58 Correct 126 ms 237360 KB Output is correct
59 Correct 137 ms 238796 KB Output is correct
60 Correct 148 ms 238884 KB Output is correct
61 Correct 139 ms 238864 KB Output is correct
62 Correct 145 ms 238924 KB Output is correct
63 Correct 137 ms 238972 KB Output is correct
64 Correct 130 ms 237772 KB Output is correct
65 Correct 134 ms 238376 KB Output is correct
66 Correct 135 ms 238408 KB Output is correct
67 Correct 134 ms 238396 KB Output is correct
68 Correct 131 ms 238144 KB Output is correct
69 Correct 135 ms 238104 KB Output is correct
70 Correct 140 ms 238956 KB Output is correct
71 Correct 244 ms 249476 KB Output is correct
72 Correct 200 ms 256460 KB Output is correct
73 Correct 1082 ms 297764 KB Output is correct
74 Correct 1033 ms 298032 KB Output is correct
75 Correct 991 ms 298232 KB Output is correct
76 Correct 1002 ms 298328 KB Output is correct
77 Correct 1030 ms 298492 KB Output is correct
78 Correct 668 ms 275712 KB Output is correct
79 Correct 325 ms 257276 KB Output is correct
80 Correct 860 ms 286900 KB Output is correct
81 Correct 848 ms 287712 KB Output is correct
82 Correct 726 ms 276476 KB Output is correct
83 Correct 745 ms 276492 KB Output is correct
84 Correct 1006 ms 298360 KB Output is correct
85 Correct 2874 ms 384644 KB Output is correct
86 Execution timed out 3081 ms 500416 KB Time limit exceeded
87 Halted 0 ms 0 KB -