답안 #63284

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
63284 2018-08-01T08:34:11 Z 윤교준(#1834) Vim (BOI13_vim) C++11
44.8889 / 100
2000 ms 127616 KB
#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define befv(V) ((V)[(sz(V)-2)])
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const bool debug = 0;
const int MAXN = 5005;

vector<pii> G[MAXN];
int D[MAXN][MAXN], E[MAXN][MAXN], F[MAXN][MAXN];
int dp[MAXN][MAXN], rdp[MAXN][MAXN];

vector<int> CV[11];
vector<int> IV;

int B[MAXN];
char A[MAXN];

int N, Ans;

int main() {
	scanf("%d %s", &N, A+1);

	{
		vector<int> V, VI(1, 0);
		for(int i = 1; i <= N; i++) {
			if('e' == A[i]) {
				Ans += 2;
				continue;
			}
			V.eb(A[i]-'a'+1);
			if('e' == A[i-1]) VI.eb(sz(V)-1);
		}

		N = sz(V);
		for(int i = 1; i <= N; i++)
			B[i] = V[i-1];
		for(int v : VI) IV.eb(v+1);
	}
	if(!Ans) {
		puts("0");
		return 0;
	}

	if(debug) {
		printf("N=%d\n", N);
		for(int i = 1; i <= N; i++)
			printf("%d ", B[i]);
		puts("");
		for(int v : IV) printf("%d ", v);
		puts("");
	}

	for(int i = 1; i <= N; i++) CV[B[i]].eb(i);
	for(int i = 2; i <= N; i++) G[i].eb(i-1, 1);
	{
		int col[11] = {0, };
		for(int i = N; i; i--) {
			for(int j = 1; j <= 10; j++)
				if(col[j]) G[i].eb(col[j], 2);
			col[B[i]] = i;
		}
	}
	
	for(int i = 1; i <= N; i++) {
		vector<int> PQ[MAXN];
		fill(D[i], D[i]+N+1, INF);
		D[i][i] = 0; PQ[0].eb(i);
		
		for(int day = 0;; day++) {
			vector<int> &V = PQ[day];
			if(V.empty()) break;

			for(int idx : V) {
				if(D[i][idx] < day) continue;

				for(auto &e : G[idx]) {
					int nidx = e.first;
					int ndst = day + e.second;

					if(D[i][nidx] <= ndst) continue;
					D[i][nidx] = ndst;
					PQ[ndst].eb(nidx);
				}
			}
		}
	}

	{
		int n = sz(IV);
		
		for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) {
			E[i][j] = D[IV[i]][IV[j]];
			F[i][j] = D[IV[j]][IV[i]];
		}

		for(int x = n-1; x--;) {
			for(int y = 0; y <= x; y++) {
				int ret = INF;
				for(int t = x+1, tmp; t < n; t++) {
					tmp = rdp[x+1][t] + E[y][t] + F[x+1][t];
					if(tmp < ret) ret = tmp;
				}
				dp[x][y] = rdp[y][x] = ret;
			}
		}
	}
	Ans += dp[0][0];

	cout << Ans << endl;
	return 0;
}

Compilation message

vim.cpp: In function 'int main()':
vim.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %s", &N, A+1);
  ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 4600 KB Output is correct
2 Correct 15 ms 5096 KB Output is correct
3 Incorrect 16 ms 5096 KB Output isn't correct
4 Correct 14 ms 5096 KB Output is correct
5 Correct 18 ms 5280 KB Output is correct
6 Correct 17 ms 6560 KB Output is correct
7 Correct 20 ms 6560 KB Output is correct
8 Correct 3 ms 6560 KB Output is correct
9 Correct 3 ms 6560 KB Output is correct
10 Correct 3 ms 6560 KB Output is correct
11 Correct 3 ms 6560 KB Output is correct
12 Correct 3 ms 6560 KB Output is correct
13 Correct 13 ms 6560 KB Output is correct
14 Correct 18 ms 6560 KB Output is correct
15 Incorrect 13 ms 6560 KB Output isn't correct
16 Correct 21 ms 6560 KB Output is correct
17 Correct 21 ms 6560 KB Output is correct
18 Correct 18 ms 6560 KB Output is correct
19 Correct 13 ms 6560 KB Output is correct
20 Correct 15 ms 6560 KB Output is correct
21 Correct 19 ms 6560 KB Output is correct
22 Correct 17 ms 6560 KB Output is correct
23 Incorrect 25 ms 6560 KB Output isn't correct
24 Incorrect 17 ms 6560 KB Output isn't correct
25 Incorrect 20 ms 6560 KB Output isn't correct
26 Correct 26 ms 6560 KB Output is correct
27 Correct 23 ms 6560 KB Output is correct
28 Correct 20 ms 6720 KB Output is correct
29 Incorrect 22 ms 6720 KB Output isn't correct
30 Correct 23 ms 6720 KB Output is correct
31 Incorrect 18 ms 6720 KB Output isn't correct
32 Correct 23 ms 6720 KB Output is correct
33 Correct 20 ms 6720 KB Output is correct
34 Incorrect 17 ms 6720 KB Output isn't correct
35 Correct 16 ms 6720 KB Output is correct
36 Correct 19 ms 6720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1302 ms 72652 KB Output is correct
2 Execution timed out 2076 ms 127616 KB Time limit exceeded
3 Correct 317 ms 127616 KB Output is correct
4 Correct 1211 ms 127616 KB Output is correct
5 Execution timed out 2074 ms 127616 KB Time limit exceeded
6 Correct 1972 ms 127616 KB Output is correct
7 Correct 1564 ms 127616 KB Output is correct
8 Correct 1433 ms 127616 KB Output is correct
9 Execution timed out 2069 ms 127616 KB Time limit exceeded
10 Execution timed out 2059 ms 127616 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Runtime error 17 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 15 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 15 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 23 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 21 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 15 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 16 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 17 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 15 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 17 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 20 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 16 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 19 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 22 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 17 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 18 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 17 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 16 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 19 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 24 ms 127616 KB Execution killed with signal 11 (could be triggered by violating memory limits)