답안 #378410

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378410 2021-03-16T17:26:10 Z YJU Vim (BOI13_vim) C++14
50 / 100
2000 ms 398428 KB
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector,Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll N=5e3+5;
const ll INF=(1LL<<60);
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define lwb lower_bound

ll nxt[N][11],dp[N][N];
string s;
vector<ll> loc;
ll n,m;

ll f(ll have,ll id){
    if(have==m)return 0;
    if(dp[have][id]!=-1)return dp[have][id];
    //cout<<have<<" "<<id<<"\n";
	dp[have][id]=INF;
	vector<ll> dis(n,INF);
    dis[id]=0;
    ll nhave=0;
    for(int i=id;i<n;i++){
		REP(j,10){
			if(nxt[i+1][j]==n||j=='e'-'a')continue;
			dis[nxt[i+1][j]]=min(dis[nxt[i+1][j]],dis[i]+2);
		}
    }
    for(int i=id;i<n;i++){

		while(nhave<m&&loc[nhave]<=i)++nhave;
		if(i==id||s[i]=='e')continue;
		if(i>loc[have])dp[have][id]=min(dp[have][id],(i-loc[have])+dis[i]+f(nhave,loc[have]+1));
		else dp[have][id]=min(dp[have][id],f(have,i)+dis[i]);
    }
    return dp[have][id];
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	memset(dp,-1,sizeof(dp));
	cin>>n>>s;
	REP(j,10)nxt[n][j]=n;
	for(int i=n-1;i>=0;i--){
		REP(j,10)nxt[i][j]=nxt[i+1][j];
        nxt[i][s[i]-'a']=i;
        if(s[i]=='e')loc.pb(i);
	}
	sort(loc.begin(),loc.end());
	m=loc.size();
	cout<<f(0,0)+m<<"\n";
	//REP(i,m)REP(j,n)cout<<i<<" "<<j<<" "<<dp[i][j]<<"\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 390 ms 197612 KB Output is correct
2 Correct 302 ms 197612 KB Output is correct
3 Correct 214 ms 197356 KB Output is correct
4 Correct 301 ms 197356 KB Output is correct
5 Correct 332 ms 197228 KB Output is correct
6 Correct 479 ms 197484 KB Output is correct
7 Correct 457 ms 197612 KB Output is correct
8 Correct 102 ms 196460 KB Output is correct
9 Correct 101 ms 196460 KB Output is correct
10 Correct 102 ms 196460 KB Output is correct
11 Correct 106 ms 196600 KB Output is correct
12 Correct 104 ms 196460 KB Output is correct
13 Correct 387 ms 197612 KB Output is correct
14 Correct 294 ms 197484 KB Output is correct
15 Correct 209 ms 197356 KB Output is correct
16 Correct 257 ms 197356 KB Output is correct
17 Correct 434 ms 197740 KB Output is correct
18 Correct 264 ms 197228 KB Output is correct
19 Correct 206 ms 196992 KB Output is correct
20 Correct 245 ms 197100 KB Output is correct
21 Correct 301 ms 197228 KB Output is correct
22 Correct 329 ms 197228 KB Output is correct
23 Correct 339 ms 197996 KB Output is correct
24 Correct 231 ms 197612 KB Output is correct
25 Correct 298 ms 197740 KB Output is correct
26 Correct 317 ms 197868 KB Output is correct
27 Correct 430 ms 197484 KB Output is correct
28 Correct 483 ms 197644 KB Output is correct
29 Correct 452 ms 197612 KB Output is correct
30 Correct 329 ms 197996 KB Output is correct
31 Correct 239 ms 197612 KB Output is correct
32 Correct 339 ms 197868 KB Output is correct
33 Correct 359 ms 197740 KB Output is correct
34 Correct 368 ms 197356 KB Output is correct
35 Correct 401 ms 197356 KB Output is correct
36 Correct 460 ms 197612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2098 ms 303980 KB Time limit exceeded
2 Execution timed out 2102 ms 300652 KB Time limit exceeded
3 Execution timed out 2098 ms 235116 KB Time limit exceeded
4 Execution timed out 2105 ms 303852 KB Time limit exceeded
5 Execution timed out 2094 ms 303744 KB Time limit exceeded
6 Execution timed out 2108 ms 338540 KB Time limit exceeded
7 Execution timed out 2081 ms 316652 KB Time limit exceeded
8 Execution timed out 2062 ms 314220 KB Time limit exceeded
9 Execution timed out 2102 ms 300652 KB Time limit exceeded
10 Execution timed out 2091 ms 306540 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Runtime error 364 ms 397932 KB Execution killed with signal 11
2 Runtime error 362 ms 398188 KB Execution killed with signal 11
3 Runtime error 375 ms 398060 KB Execution killed with signal 11
4 Runtime error 366 ms 398188 KB Execution killed with signal 11
5 Runtime error 362 ms 398060 KB Execution killed with signal 11
6 Runtime error 363 ms 398120 KB Execution killed with signal 11
7 Runtime error 405 ms 397932 KB Execution killed with signal 11
8 Runtime error 360 ms 397932 KB Execution killed with signal 11
9 Runtime error 360 ms 398188 KB Execution killed with signal 11
10 Runtime error 384 ms 398124 KB Execution killed with signal 11
11 Runtime error 363 ms 398188 KB Execution killed with signal 11
12 Runtime error 358 ms 398060 KB Execution killed with signal 11
13 Runtime error 371 ms 398428 KB Execution killed with signal 11
14 Runtime error 362 ms 398208 KB Execution killed with signal 11
15 Runtime error 377 ms 398060 KB Execution killed with signal 11
16 Runtime error 369 ms 398060 KB Execution killed with signal 11
17 Runtime error 362 ms 398188 KB Execution killed with signal 11
18 Runtime error 366 ms 397996 KB Execution killed with signal 11
19 Runtime error 361 ms 397932 KB Execution killed with signal 11
20 Runtime error 401 ms 397932 KB Execution killed with signal 11