답안 #567849

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
567849 2022-05-24T09:21:13 Z jamezzz Copy and Paste 3 (JOI22_copypaste3) C++17
30 / 100
3000 ms 1963044 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#define getchar_unlocked getchar
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
#define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin());
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));

#define mod 1000000007
#define mod2 1000000009

inline int add(int a,int b){
	int r=a+b;
	while(r>=mod)r-=mod;
	while(r<0)r+=mod;
	return r;
}

inline int mult(int a,int b){
	return (int)(((ll)(a*b))%mod);
}

inline int rd(){
	int x=0;
	char ch=getchar_unlocked();
	while(!(ch&16))ch=getchar();//keep reading while current character is whitespace
    while(ch&16){//this will break when ‘\n’ or ‘ ‘ is encountered
		x=(x<<3)+(x<<1)+(ch&15);
		ch=getchar_unlocked();
	}
	return x;
}

int n,a,b,c,cnt;
char s[2505];
int hh[2505][2505],num[2505*2505];
map<ii,int> mp;
vector<ii> v[2505*2505];
vector<int> pos[2505];
ll memo[2505][2505];
unordered_map<int,int> vis[2505][2505];

ll dp(int l,int r){
	if(l==r)return a;
	if(l+1==r){
		if(s[l]!=s[r])return 2*a;
		return min((ll)2*a,(ll)a+b+2*c);
	}
	if(memo[l][r]!=-1)return memo[l][r];
	ll ans=(ll)(r-l+1)*a;
	for(int i=l;i<=r;++i){
		for(int j:pos[i]){
			if(j>r/2+1)break;
			int x=hh[i][j];
			if(vis[l][r][x]!=0)continue;
			vis[l][r][x]=1;
			int far=l-1,cnt=0;
			for(int i=lower_bound(all(v[x]),ii(l,l))-v[x].begin();i<sz(v[x]);++i){
				ii pr=v[x][i];
				if(pr.se>r)break;
				if(far<pr.fi&&pr.se<=r){
					++cnt;
					far=pr.se;
				}
			}
			if(cnt==1)continue;
			ans=min(ans,dp(v[x][0].fi,v[x][0].se)+b+(ll)cnt*c+(ll)(r-l+1-cnt*(j-i+1))*a);
		}
	}
	return memo[l][r]=ans;
}

int main(){
	sf("%d",&n);
	sf(" %s",&s);
	sf("%d%d%d",&a,&b,&c);
	for(int i=0;i<n;++i){
		ll cur=0,cur2=0;
		ll pw=1,pw2=1;
		for(int j=i;j<n;++j){
			cur+=pw*(s[j]-'a'+1);
			cur2+=pw2*(s[j]-'a'+1);
			cur%=mod;
			cur2%=mod2;
			pw*=31;pw%=mod;
			pw2*=31;pw2%=mod2;
			ii pr=ii((int)cur,(int)cur2);
			if(!mp.count(pr)){
				mp[pr]=cnt++;
			}
			hh[i][j]=mp[pr];
			v[hh[i][j]].pb({i,j});
		}
	}
	
	for(int i=n-1;i>=0;--i){
		for(int j=i;j<n;++j){
			if(num[hh[i][j]]!=0)pos[i].pb(j);
			++num[hh[i][j]];
		}
	}
	
	for(int i=0;i<=n;++i){
		for(int j=0;j<=n;++j){
			memo[i][j]=-1;
		}
	}
	
	pf("%lld\n",dp(0,n-1));
}

Compilation message

copypaste3.cpp: In function 'int main()':
copypaste3.cpp:99:8: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[2505]' [-Wformat=]
   99 |  sf(" %s",&s);
      |       ~^  ~~
      |        |  |
      |        |  char (*)[2505]
      |        char*
copypaste3.cpp:98:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |  sf("%d",&n);
      |    ^
copypaste3.cpp:99:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |  sf(" %s",&s);
      |    ^
copypaste3.cpp:100:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |  sf("%d%d%d",&a,&b,&c);
      |    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 269 ms 491632 KB Output is correct
2 Correct 240 ms 491696 KB Output is correct
3 Correct 262 ms 491576 KB Output is correct
4 Correct 262 ms 491592 KB Output is correct
5 Correct 252 ms 491548 KB Output is correct
6 Correct 250 ms 491632 KB Output is correct
7 Correct 250 ms 491548 KB Output is correct
8 Correct 243 ms 491588 KB Output is correct
9 Correct 259 ms 491668 KB Output is correct
10 Correct 245 ms 491596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 253 ms 491696 KB Output is correct
2 Correct 250 ms 491624 KB Output is correct
3 Correct 873 ms 575000 KB Output is correct
4 Correct 1000 ms 586924 KB Output is correct
5 Correct 1192 ms 598688 KB Output is correct
6 Correct 1359 ms 612388 KB Output is correct
7 Correct 1646 ms 629400 KB Output is correct
8 Correct 1628 ms 629332 KB Output is correct
9 Correct 1597 ms 629376 KB Output is correct
10 Correct 240 ms 491524 KB Output is correct
11 Correct 243 ms 491504 KB Output is correct
12 Correct 246 ms 491468 KB Output is correct
13 Correct 238 ms 491724 KB Output is correct
14 Correct 248 ms 491628 KB Output is correct
15 Correct 240 ms 491672 KB Output is correct
16 Correct 243 ms 491724 KB Output is correct
17 Correct 244 ms 491664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 269 ms 491632 KB Output is correct
2 Correct 240 ms 491696 KB Output is correct
3 Correct 262 ms 491576 KB Output is correct
4 Correct 262 ms 491592 KB Output is correct
5 Correct 252 ms 491548 KB Output is correct
6 Correct 250 ms 491632 KB Output is correct
7 Correct 250 ms 491548 KB Output is correct
8 Correct 243 ms 491588 KB Output is correct
9 Correct 259 ms 491668 KB Output is correct
10 Correct 245 ms 491596 KB Output is correct
11 Correct 244 ms 491548 KB Output is correct
12 Correct 243 ms 491624 KB Output is correct
13 Correct 245 ms 491612 KB Output is correct
14 Correct 239 ms 491632 KB Output is correct
15 Correct 247 ms 491724 KB Output is correct
16 Correct 245 ms 491632 KB Output is correct
17 Correct 270 ms 491548 KB Output is correct
18 Correct 261 ms 491496 KB Output is correct
19 Correct 244 ms 491724 KB Output is correct
20 Correct 243 ms 491600 KB Output is correct
21 Correct 255 ms 491740 KB Output is correct
22 Correct 241 ms 491852 KB Output is correct
23 Correct 250 ms 491856 KB Output is correct
24 Correct 238 ms 491852 KB Output is correct
25 Correct 243 ms 491856 KB Output is correct
26 Correct 260 ms 491836 KB Output is correct
27 Correct 241 ms 491856 KB Output is correct
28 Correct 272 ms 491752 KB Output is correct
29 Correct 246 ms 491856 KB Output is correct
30 Correct 244 ms 491856 KB Output is correct
31 Correct 245 ms 491856 KB Output is correct
32 Correct 242 ms 491876 KB Output is correct
33 Correct 243 ms 491860 KB Output is correct
34 Correct 250 ms 491492 KB Output is correct
35 Correct 242 ms 491584 KB Output is correct
36 Correct 241 ms 491508 KB Output is correct
37 Correct 245 ms 491592 KB Output is correct
38 Correct 255 ms 491676 KB Output is correct
39 Correct 250 ms 491728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 269 ms 491632 KB Output is correct
2 Correct 240 ms 491696 KB Output is correct
3 Correct 262 ms 491576 KB Output is correct
4 Correct 262 ms 491592 KB Output is correct
5 Correct 252 ms 491548 KB Output is correct
6 Correct 250 ms 491632 KB Output is correct
7 Correct 250 ms 491548 KB Output is correct
8 Correct 243 ms 491588 KB Output is correct
9 Correct 259 ms 491668 KB Output is correct
10 Correct 245 ms 491596 KB Output is correct
11 Correct 244 ms 491548 KB Output is correct
12 Correct 243 ms 491624 KB Output is correct
13 Correct 245 ms 491612 KB Output is correct
14 Correct 239 ms 491632 KB Output is correct
15 Correct 247 ms 491724 KB Output is correct
16 Correct 245 ms 491632 KB Output is correct
17 Correct 270 ms 491548 KB Output is correct
18 Correct 261 ms 491496 KB Output is correct
19 Correct 244 ms 491724 KB Output is correct
20 Correct 243 ms 491600 KB Output is correct
21 Correct 255 ms 491740 KB Output is correct
22 Correct 241 ms 491852 KB Output is correct
23 Correct 250 ms 491856 KB Output is correct
24 Correct 238 ms 491852 KB Output is correct
25 Correct 243 ms 491856 KB Output is correct
26 Correct 260 ms 491836 KB Output is correct
27 Correct 241 ms 491856 KB Output is correct
28 Correct 272 ms 491752 KB Output is correct
29 Correct 246 ms 491856 KB Output is correct
30 Correct 244 ms 491856 KB Output is correct
31 Correct 245 ms 491856 KB Output is correct
32 Correct 242 ms 491876 KB Output is correct
33 Correct 243 ms 491860 KB Output is correct
34 Correct 250 ms 491492 KB Output is correct
35 Correct 242 ms 491584 KB Output is correct
36 Correct 241 ms 491508 KB Output is correct
37 Correct 245 ms 491592 KB Output is correct
38 Correct 255 ms 491676 KB Output is correct
39 Correct 250 ms 491728 KB Output is correct
40 Correct 244 ms 492588 KB Output is correct
41 Correct 248 ms 494028 KB Output is correct
42 Correct 251 ms 495452 KB Output is correct
43 Correct 260 ms 495484 KB Output is correct
44 Correct 253 ms 495464 KB Output is correct
45 Correct 254 ms 495508 KB Output is correct
46 Correct 250 ms 495504 KB Output is correct
47 Correct 319 ms 516968 KB Output is correct
48 Correct 299 ms 508284 KB Output is correct
49 Correct 300 ms 515404 KB Output is correct
50 Correct 291 ms 512112 KB Output is correct
51 Correct 318 ms 511924 KB Output is correct
52 Correct 303 ms 512224 KB Output is correct
53 Correct 256 ms 495440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 269 ms 491632 KB Output is correct
2 Correct 240 ms 491696 KB Output is correct
3 Correct 262 ms 491576 KB Output is correct
4 Correct 262 ms 491592 KB Output is correct
5 Correct 252 ms 491548 KB Output is correct
6 Correct 250 ms 491632 KB Output is correct
7 Correct 250 ms 491548 KB Output is correct
8 Correct 243 ms 491588 KB Output is correct
9 Correct 259 ms 491668 KB Output is correct
10 Correct 245 ms 491596 KB Output is correct
11 Correct 244 ms 491548 KB Output is correct
12 Correct 243 ms 491624 KB Output is correct
13 Correct 245 ms 491612 KB Output is correct
14 Correct 239 ms 491632 KB Output is correct
15 Correct 247 ms 491724 KB Output is correct
16 Correct 245 ms 491632 KB Output is correct
17 Correct 270 ms 491548 KB Output is correct
18 Correct 261 ms 491496 KB Output is correct
19 Correct 244 ms 491724 KB Output is correct
20 Correct 243 ms 491600 KB Output is correct
21 Correct 255 ms 491740 KB Output is correct
22 Correct 241 ms 491852 KB Output is correct
23 Correct 250 ms 491856 KB Output is correct
24 Correct 238 ms 491852 KB Output is correct
25 Correct 243 ms 491856 KB Output is correct
26 Correct 260 ms 491836 KB Output is correct
27 Correct 241 ms 491856 KB Output is correct
28 Correct 272 ms 491752 KB Output is correct
29 Correct 246 ms 491856 KB Output is correct
30 Correct 244 ms 491856 KB Output is correct
31 Correct 245 ms 491856 KB Output is correct
32 Correct 242 ms 491876 KB Output is correct
33 Correct 243 ms 491860 KB Output is correct
34 Correct 250 ms 491492 KB Output is correct
35 Correct 242 ms 491584 KB Output is correct
36 Correct 241 ms 491508 KB Output is correct
37 Correct 245 ms 491592 KB Output is correct
38 Correct 255 ms 491676 KB Output is correct
39 Correct 250 ms 491728 KB Output is correct
40 Correct 244 ms 492588 KB Output is correct
41 Correct 248 ms 494028 KB Output is correct
42 Correct 251 ms 495452 KB Output is correct
43 Correct 260 ms 495484 KB Output is correct
44 Correct 253 ms 495464 KB Output is correct
45 Correct 254 ms 495508 KB Output is correct
46 Correct 250 ms 495504 KB Output is correct
47 Correct 319 ms 516968 KB Output is correct
48 Correct 299 ms 508284 KB Output is correct
49 Correct 300 ms 515404 KB Output is correct
50 Correct 291 ms 512112 KB Output is correct
51 Correct 318 ms 511924 KB Output is correct
52 Correct 303 ms 512224 KB Output is correct
53 Correct 256 ms 495440 KB Output is correct
54 Correct 320 ms 506688 KB Output is correct
55 Correct 389 ms 520112 KB Output is correct
56 Correct 777 ms 557940 KB Output is correct
57 Correct 785 ms 558040 KB Output is correct
58 Correct 826 ms 558092 KB Output is correct
59 Correct 792 ms 558204 KB Output is correct
60 Correct 828 ms 558356 KB Output is correct
61 Execution timed out 3147 ms 1963044 KB Time limit exceeded
62 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 269 ms 491632 KB Output is correct
2 Correct 240 ms 491696 KB Output is correct
3 Correct 262 ms 491576 KB Output is correct
4 Correct 262 ms 491592 KB Output is correct
5 Correct 252 ms 491548 KB Output is correct
6 Correct 250 ms 491632 KB Output is correct
7 Correct 250 ms 491548 KB Output is correct
8 Correct 243 ms 491588 KB Output is correct
9 Correct 259 ms 491668 KB Output is correct
10 Correct 245 ms 491596 KB Output is correct
11 Correct 253 ms 491696 KB Output is correct
12 Correct 250 ms 491624 KB Output is correct
13 Correct 873 ms 575000 KB Output is correct
14 Correct 1000 ms 586924 KB Output is correct
15 Correct 1192 ms 598688 KB Output is correct
16 Correct 1359 ms 612388 KB Output is correct
17 Correct 1646 ms 629400 KB Output is correct
18 Correct 1628 ms 629332 KB Output is correct
19 Correct 1597 ms 629376 KB Output is correct
20 Correct 240 ms 491524 KB Output is correct
21 Correct 243 ms 491504 KB Output is correct
22 Correct 246 ms 491468 KB Output is correct
23 Correct 238 ms 491724 KB Output is correct
24 Correct 248 ms 491628 KB Output is correct
25 Correct 240 ms 491672 KB Output is correct
26 Correct 243 ms 491724 KB Output is correct
27 Correct 244 ms 491664 KB Output is correct
28 Correct 244 ms 491548 KB Output is correct
29 Correct 243 ms 491624 KB Output is correct
30 Correct 245 ms 491612 KB Output is correct
31 Correct 239 ms 491632 KB Output is correct
32 Correct 247 ms 491724 KB Output is correct
33 Correct 245 ms 491632 KB Output is correct
34 Correct 270 ms 491548 KB Output is correct
35 Correct 261 ms 491496 KB Output is correct
36 Correct 244 ms 491724 KB Output is correct
37 Correct 243 ms 491600 KB Output is correct
38 Correct 255 ms 491740 KB Output is correct
39 Correct 241 ms 491852 KB Output is correct
40 Correct 250 ms 491856 KB Output is correct
41 Correct 238 ms 491852 KB Output is correct
42 Correct 243 ms 491856 KB Output is correct
43 Correct 260 ms 491836 KB Output is correct
44 Correct 241 ms 491856 KB Output is correct
45 Correct 272 ms 491752 KB Output is correct
46 Correct 246 ms 491856 KB Output is correct
47 Correct 244 ms 491856 KB Output is correct
48 Correct 245 ms 491856 KB Output is correct
49 Correct 242 ms 491876 KB Output is correct
50 Correct 243 ms 491860 KB Output is correct
51 Correct 250 ms 491492 KB Output is correct
52 Correct 242 ms 491584 KB Output is correct
53 Correct 241 ms 491508 KB Output is correct
54 Correct 245 ms 491592 KB Output is correct
55 Correct 255 ms 491676 KB Output is correct
56 Correct 250 ms 491728 KB Output is correct
57 Correct 244 ms 492588 KB Output is correct
58 Correct 248 ms 494028 KB Output is correct
59 Correct 251 ms 495452 KB Output is correct
60 Correct 260 ms 495484 KB Output is correct
61 Correct 253 ms 495464 KB Output is correct
62 Correct 254 ms 495508 KB Output is correct
63 Correct 250 ms 495504 KB Output is correct
64 Correct 319 ms 516968 KB Output is correct
65 Correct 299 ms 508284 KB Output is correct
66 Correct 300 ms 515404 KB Output is correct
67 Correct 291 ms 512112 KB Output is correct
68 Correct 318 ms 511924 KB Output is correct
69 Correct 303 ms 512224 KB Output is correct
70 Correct 256 ms 495440 KB Output is correct
71 Correct 320 ms 506688 KB Output is correct
72 Correct 389 ms 520112 KB Output is correct
73 Correct 777 ms 557940 KB Output is correct
74 Correct 785 ms 558040 KB Output is correct
75 Correct 826 ms 558092 KB Output is correct
76 Correct 792 ms 558204 KB Output is correct
77 Correct 828 ms 558356 KB Output is correct
78 Execution timed out 3147 ms 1963044 KB Time limit exceeded
79 Halted 0 ms 0 KB -