답안 #733280

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
733280 2023-04-30T11:23:05 Z kym Copy and Paste 3 (JOI22_copypaste3) C++14
25 / 100
3000 ms 104492 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define FOR(i,s,e) for(int i = s; i <= (int)e; ++i)
#define DEC(i,s,e) for(int i = s; i >= (int)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
#define reach cerr << "LINE: " << __LINE__ << "\n";
#else
#define reach 
#define db(x)
#define db2(x,y)
#define db3(a,b,c)
#define dbv(v)
#define dbvp(v)
#define dba(a,ss,ee)
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define f first 
#define s second
#define g0(x) get<0>(x)
#define g1(x) get<1>(x)
#define g2(x) get<2>(x)
#define g3(x) get<3>(x)
typedef pair <int, int> pi;
typedef tuple<int,int,int> ti3;
typedef tuple<int,int,int,int> ti4;
int rand(int a, int b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (long long)1e18 + 500;
template <typename T> void chmax(T& a, const T b) { a=max(a,b); }
template <typename T> void chmin(T& a, const T b) { a=min(a,b); }
const int MAXN = 2505;
int H[MAXN][MAXN];
int n;
int A,B,C;
int s[MAXN];
int T[MAXN];
int qexp(int a, int b, int mod){
	int res=1;
	while(b){
		if(b&1)res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}
unordered_map<int,vector<pi>> V;
unordered_map<int,int> dp2;
int dpdp(int l, int r);
int imp;
int transit(int hash){
	
	if(dp2.find(hash)!=dp2.end())return dp2[hash];
	if(hash==imp)reach;
	int L=V[hash][0].s-V[hash][0].f+1;

	vector<int> pts;
	vector<int> sts,ens;
	unordered_map<int,vector<int>> vv;
	for(auto seg:V[hash]){
		sts.pb(seg.f-1);
		pts.pb(seg.f-1);
		pts.pb(seg.s);
		ens.pb(seg.s);
	}
	sort(all(sts));
	sts.resize(unique(all(sts))-sts.begin());

	sort(all(ens));
	ens.resize(unique(all(ens))-ens.begin());

	sort(all(pts));
	pts.resize(unique(all(pts))-pts.begin());

	for(auto seg:V[hash]){
		int l=lower_bound(all(pts),seg.f-1)-pts.begin();
		int r=lower_bound(all(pts),seg.s)-pts.begin();
		vv[r].pb(l);
	}
	if(imp==hash){
		dbv(sts);
	}
	int ans=oo;
	FOR(l,0,sts.size()-1){
		vector<int> mn;
		int idx=0;
		unordered_map<int,int> mp;
		if(imp==hash)db(l);
		FOR(i,0,pts.size()-1){
			if(pts[i]<sts[l])continue;
			if(pts[i]==sts[l]){
				mp[pts[i]]=0;
				mn.pb(0);
				continue;
			}
			++idx;
			mp[pts[i]]=idx;
			int val=oo;
			if(imp==hash){
				dbv(vv[i]);
			}
			for(auto x:vv[i]){
				
				if(pts[x]>=sts[l]) {
					chmin(val,mn[mp[pts[x]]]+C);

				}
			}
			chmin(val,mn.back()+A*(pts[i]-pts[i-1]));

			mn.pb(val);
			if(imp==hash){
				dbv(mn);
			}
			if(pts[i]-sts[l]>=L*2)chmin(ans, val+dpdp(sts[l]+1,pts[i]));
		}
	}
	return dp2[hash]=ans;
}
int dp1[MAXN][MAXN];
int dpdp(int l, int r){
	if(~dp1[l][r]) return dp1[l][r];
	if(l==1&&r==n)return 0;
	int ans=oo;
	if(r!=n)chmin(ans,dpdp(l,r+1)+A);
	if(l!=1)chmin(ans,dpdp(l-1,r)+A);
	chmin(ans,transit(H[l][r])+B);
	//db3(l,r,ans);
	return dp1[l][r]=ans;
}
int32_t main() 
{
	IAMSPEED
	memset(dp1,-1,sizeof dp1);
	cin >> n;
	FOR(i,1,n){
		char ch; cin >> ch;
		s[i]=ch-'a'+1;
	}
	cin >> A >> B >> C;
	FOR(i,1,n){
		int val=qexp(27,i,MOD)*s[i];
		T[i]=T[i-1]+val;
	}
	FOR(i,1,n){
		FOR(j,i,n){
			int d=qexp(27,i-1,MOD);
			H[i][j]=((T[j]-T[i-1]+MOD)%MOD)*qexp(d,MOD-2,MOD)%MOD;
			V[H[i][j]].pb({i,j});
		}
	}
	//imp=H[2][4];
	//cerr<<transit(H[2][4]);
	//exit(0);
	int ans=oo;
	FOR(i,1,n){
		int res=dpdp(i,i)+A;
		chmin(ans,res);
	}
	cout<<ans;
}



# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 49328 KB Output is correct
2 Correct 21 ms 49448 KB Output is correct
3 Correct 18 ms 49364 KB Output is correct
4 Correct 18 ms 49392 KB Output is correct
5 Correct 18 ms 49364 KB Output is correct
6 Correct 18 ms 49352 KB Output is correct
7 Correct 20 ms 49464 KB Output is correct
8 Correct 20 ms 49364 KB Output is correct
9 Correct 18 ms 49452 KB Output is correct
10 Correct 22 ms 49420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 49484 KB Output is correct
2 Correct 18 ms 49368 KB Output is correct
3 Execution timed out 3076 ms 104492 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 49328 KB Output is correct
2 Correct 21 ms 49448 KB Output is correct
3 Correct 18 ms 49364 KB Output is correct
4 Correct 18 ms 49392 KB Output is correct
5 Correct 18 ms 49364 KB Output is correct
6 Correct 18 ms 49352 KB Output is correct
7 Correct 20 ms 49464 KB Output is correct
8 Correct 20 ms 49364 KB Output is correct
9 Correct 18 ms 49452 KB Output is correct
10 Correct 22 ms 49420 KB Output is correct
11 Correct 18 ms 49432 KB Output is correct
12 Correct 18 ms 49520 KB Output is correct
13 Correct 21 ms 49484 KB Output is correct
14 Correct 21 ms 49452 KB Output is correct
15 Correct 18 ms 49500 KB Output is correct
16 Correct 20 ms 49404 KB Output is correct
17 Correct 18 ms 49364 KB Output is correct
18 Correct 18 ms 49364 KB Output is correct
19 Correct 19 ms 49492 KB Output is correct
20 Correct 20 ms 49448 KB Output is correct
21 Correct 20 ms 49604 KB Output is correct
22 Correct 18 ms 49532 KB Output is correct
23 Correct 19 ms 49600 KB Output is correct
24 Correct 19 ms 49572 KB Output is correct
25 Correct 19 ms 49556 KB Output is correct
26 Correct 20 ms 49532 KB Output is correct
27 Correct 21 ms 49584 KB Output is correct
28 Correct 18 ms 49484 KB Output is correct
29 Correct 20 ms 49620 KB Output is correct
30 Correct 20 ms 49620 KB Output is correct
31 Correct 20 ms 49536 KB Output is correct
32 Correct 19 ms 49520 KB Output is correct
33 Correct 19 ms 49544 KB Output is correct
34 Correct 19 ms 49376 KB Output is correct
35 Correct 18 ms 49452 KB Output is correct
36 Correct 19 ms 49364 KB Output is correct
37 Correct 19 ms 49356 KB Output is correct
38 Correct 19 ms 49456 KB Output is correct
39 Correct 20 ms 49576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 49328 KB Output is correct
2 Correct 21 ms 49448 KB Output is correct
3 Correct 18 ms 49364 KB Output is correct
4 Correct 18 ms 49392 KB Output is correct
5 Correct 18 ms 49364 KB Output is correct
6 Correct 18 ms 49352 KB Output is correct
7 Correct 20 ms 49464 KB Output is correct
8 Correct 20 ms 49364 KB Output is correct
9 Correct 18 ms 49452 KB Output is correct
10 Correct 22 ms 49420 KB Output is correct
11 Correct 18 ms 49432 KB Output is correct
12 Correct 18 ms 49520 KB Output is correct
13 Correct 21 ms 49484 KB Output is correct
14 Correct 21 ms 49452 KB Output is correct
15 Correct 18 ms 49500 KB Output is correct
16 Correct 20 ms 49404 KB Output is correct
17 Correct 18 ms 49364 KB Output is correct
18 Correct 18 ms 49364 KB Output is correct
19 Correct 19 ms 49492 KB Output is correct
20 Correct 20 ms 49448 KB Output is correct
21 Correct 20 ms 49604 KB Output is correct
22 Correct 18 ms 49532 KB Output is correct
23 Correct 19 ms 49600 KB Output is correct
24 Correct 19 ms 49572 KB Output is correct
25 Correct 19 ms 49556 KB Output is correct
26 Correct 20 ms 49532 KB Output is correct
27 Correct 21 ms 49584 KB Output is correct
28 Correct 18 ms 49484 KB Output is correct
29 Correct 20 ms 49620 KB Output is correct
30 Correct 20 ms 49620 KB Output is correct
31 Correct 20 ms 49536 KB Output is correct
32 Correct 19 ms 49520 KB Output is correct
33 Correct 19 ms 49544 KB Output is correct
34 Correct 19 ms 49376 KB Output is correct
35 Correct 18 ms 49452 KB Output is correct
36 Correct 19 ms 49364 KB Output is correct
37 Correct 19 ms 49356 KB Output is correct
38 Correct 19 ms 49456 KB Output is correct
39 Correct 20 ms 49576 KB Output is correct
40 Correct 25 ms 50228 KB Output is correct
41 Correct 209 ms 50956 KB Output is correct
42 Correct 46 ms 52812 KB Output is correct
43 Correct 48 ms 52912 KB Output is correct
44 Correct 56 ms 52872 KB Output is correct
45 Correct 43 ms 52940 KB Output is correct
46 Correct 46 ms 52984 KB Output is correct
47 Correct 46 ms 51364 KB Output is correct
48 Correct 43 ms 52136 KB Output is correct
49 Correct 43 ms 52436 KB Output is correct
50 Correct 43 ms 52444 KB Output is correct
51 Correct 48 ms 52124 KB Output is correct
52 Correct 49 ms 52080 KB Output is correct
53 Correct 47 ms 52852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 49328 KB Output is correct
2 Correct 21 ms 49448 KB Output is correct
3 Correct 18 ms 49364 KB Output is correct
4 Correct 18 ms 49392 KB Output is correct
5 Correct 18 ms 49364 KB Output is correct
6 Correct 18 ms 49352 KB Output is correct
7 Correct 20 ms 49464 KB Output is correct
8 Correct 20 ms 49364 KB Output is correct
9 Correct 18 ms 49452 KB Output is correct
10 Correct 22 ms 49420 KB Output is correct
11 Correct 18 ms 49432 KB Output is correct
12 Correct 18 ms 49520 KB Output is correct
13 Correct 21 ms 49484 KB Output is correct
14 Correct 21 ms 49452 KB Output is correct
15 Correct 18 ms 49500 KB Output is correct
16 Correct 20 ms 49404 KB Output is correct
17 Correct 18 ms 49364 KB Output is correct
18 Correct 18 ms 49364 KB Output is correct
19 Correct 19 ms 49492 KB Output is correct
20 Correct 20 ms 49448 KB Output is correct
21 Correct 20 ms 49604 KB Output is correct
22 Correct 18 ms 49532 KB Output is correct
23 Correct 19 ms 49600 KB Output is correct
24 Correct 19 ms 49572 KB Output is correct
25 Correct 19 ms 49556 KB Output is correct
26 Correct 20 ms 49532 KB Output is correct
27 Correct 21 ms 49584 KB Output is correct
28 Correct 18 ms 49484 KB Output is correct
29 Correct 20 ms 49620 KB Output is correct
30 Correct 20 ms 49620 KB Output is correct
31 Correct 20 ms 49536 KB Output is correct
32 Correct 19 ms 49520 KB Output is correct
33 Correct 19 ms 49544 KB Output is correct
34 Correct 19 ms 49376 KB Output is correct
35 Correct 18 ms 49452 KB Output is correct
36 Correct 19 ms 49364 KB Output is correct
37 Correct 19 ms 49356 KB Output is correct
38 Correct 19 ms 49456 KB Output is correct
39 Correct 20 ms 49576 KB Output is correct
40 Correct 25 ms 50228 KB Output is correct
41 Correct 209 ms 50956 KB Output is correct
42 Correct 46 ms 52812 KB Output is correct
43 Correct 48 ms 52912 KB Output is correct
44 Correct 56 ms 52872 KB Output is correct
45 Correct 43 ms 52940 KB Output is correct
46 Correct 46 ms 52984 KB Output is correct
47 Correct 46 ms 51364 KB Output is correct
48 Correct 43 ms 52136 KB Output is correct
49 Correct 43 ms 52436 KB Output is correct
50 Correct 43 ms 52444 KB Output is correct
51 Correct 48 ms 52124 KB Output is correct
52 Correct 49 ms 52080 KB Output is correct
53 Correct 47 ms 52852 KB Output is correct
54 Correct 208 ms 65728 KB Output is correct
55 Execution timed out 3066 ms 67896 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 49328 KB Output is correct
2 Correct 21 ms 49448 KB Output is correct
3 Correct 18 ms 49364 KB Output is correct
4 Correct 18 ms 49392 KB Output is correct
5 Correct 18 ms 49364 KB Output is correct
6 Correct 18 ms 49352 KB Output is correct
7 Correct 20 ms 49464 KB Output is correct
8 Correct 20 ms 49364 KB Output is correct
9 Correct 18 ms 49452 KB Output is correct
10 Correct 22 ms 49420 KB Output is correct
11 Correct 20 ms 49484 KB Output is correct
12 Correct 18 ms 49368 KB Output is correct
13 Execution timed out 3076 ms 104492 KB Time limit exceeded
14 Halted 0 ms 0 KB -