Submission #63269

# Submission time Handle Problem Language Result Execution time Memory
63269 2018-08-01T08:08:49 Z 김세빈(#1833) Vim (BOI13_vim) C++11
50 / 100
90 ms 6632 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair <int, int> pii;

vector <pii> V[70707];
vector <int> K;
int D[5050][5050];
int dp[5050][5050];
int N[70707], chk[70707];
priority_queue <pii, vector <pii>, greater <pii>> Q;
char str[70707];
int n, ans;

int main()
{
	int i, j, k;
	pii p;
	
	scanf("%d%s", &n, str);
	
	if(n > 500) return 0;
	
	for(i=0; i<n; i++){
		if(str[i] == 'e') K.push_back(i);
	}
	
	for(i=1; i<n; i++){
		V[i].push_back(pii(i-1, 1));
	}
	
	for(i=0; i<n; i++){
		for(j=0; j<10; j++){
			if(j == 4) continue;
			for(k=i+1; k<n; k++) if(str[k] == j + 'a') break;
			if(k < n) V[i].push_back(pii(k, 2));
		}
		
		if(str[i] == 'e'){
			for(j=i+1; j<n; j++) if(str[j] != 'e') break;
			N[i] = j;
		}
	}
	
	for(i=0; i<n; i++){
		for(j=0; j<n; j++) chk[j] = 0;
		
		Q.push(pii(0, i));
		
		for(; !Q.empty(); ){
			p = Q.top(); Q.pop();
			if(chk[p.second]) continue;
			D[i][p.second] = p.first;
			chk[p.second] = 1;
			
			for(pii t: V[p.second]){
				if(!chk[t.first]){
					Q.push(pii(p.first + t.second, t.first));
				}
			}
		}
	}
	
	for(i=0; i<K.size(); i++){
		dp[i][0] = D[0][K[i]] + D[K[i]][K[0]];
		for(j=1; j<=i; j++){
			dp[i][j] = 1e9;
			for(k=0; k<j; k++){
				dp[i][j] = min(dp[i][j], dp[j-1][k] + D[N[K[k]]][K[i]] + D[K[i]][K[j]]);
			}
		}
	}
	
	ans = 1e9;
	
	for(i=0; i<K.size(); i++) ans = min(ans, dp[K.size() - 1][i]);
	
	printf("%d\n", ans + K.size());
	
	return 0;
}

Compilation message

vim.cpp: In function 'int main()':
vim.cpp:65:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0; i<K.size(); i++){
           ~^~~~~~~~~
vim.cpp:77:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0; i<K.size(); i++) ans = min(ans, dp[K.size() - 1][i]);
           ~^~~~~~~~~
vim.cpp:79:31: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n", ans + K.size());
                 ~~~~~~~~~~~~~~^
vim.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%s", &n, str);
  ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 56 ms 6396 KB Output is correct
2 Correct 36 ms 6396 KB Output is correct
3 Correct 24 ms 6396 KB Output is correct
4 Correct 48 ms 6396 KB Output is correct
5 Correct 63 ms 6396 KB Output is correct
6 Correct 84 ms 6396 KB Output is correct
7 Correct 73 ms 6396 KB Output is correct
8 Correct 4 ms 6396 KB Output is correct
9 Correct 5 ms 6396 KB Output is correct
10 Correct 4 ms 6396 KB Output is correct
11 Correct 4 ms 6396 KB Output is correct
12 Correct 4 ms 6396 KB Output is correct
13 Correct 57 ms 6632 KB Output is correct
14 Correct 31 ms 6632 KB Output is correct
15 Correct 24 ms 6632 KB Output is correct
16 Correct 37 ms 6632 KB Output is correct
17 Correct 78 ms 6632 KB Output is correct
18 Correct 42 ms 6632 KB Output is correct
19 Correct 25 ms 6632 KB Output is correct
20 Correct 33 ms 6632 KB Output is correct
21 Correct 50 ms 6632 KB Output is correct
22 Correct 58 ms 6632 KB Output is correct
23 Correct 33 ms 6632 KB Output is correct
24 Correct 66 ms 6632 KB Output is correct
25 Correct 58 ms 6632 KB Output is correct
26 Correct 59 ms 6632 KB Output is correct
27 Correct 85 ms 6632 KB Output is correct
28 Correct 90 ms 6632 KB Output is correct
29 Correct 71 ms 6632 KB Output is correct
30 Correct 49 ms 6632 KB Output is correct
31 Correct 67 ms 6632 KB Output is correct
32 Correct 77 ms 6632 KB Output is correct
33 Correct 64 ms 6632 KB Output is correct
34 Correct 70 ms 6632 KB Output is correct
35 Correct 63 ms 6632 KB Output is correct
36 Correct 65 ms 6632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 6632 KB Output isn't correct
2 Incorrect 3 ms 6632 KB Output isn't correct
3 Incorrect 4 ms 6632 KB Output isn't correct
4 Incorrect 3 ms 6632 KB Output isn't correct
5 Incorrect 3 ms 6632 KB Output isn't correct
6 Incorrect 4 ms 6632 KB Output isn't correct
7 Incorrect 3 ms 6632 KB Output isn't correct
8 Incorrect 4 ms 6632 KB Output isn't correct
9 Incorrect 3 ms 6632 KB Output isn't correct
10 Incorrect 3 ms 6632 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 6632 KB Output isn't correct
2 Incorrect 5 ms 6632 KB Output isn't correct
3 Incorrect 3 ms 6632 KB Output isn't correct
4 Incorrect 4 ms 6632 KB Output isn't correct
5 Incorrect 4 ms 6632 KB Output isn't correct
6 Incorrect 5 ms 6632 KB Output isn't correct
7 Incorrect 5 ms 6632 KB Output isn't correct
8 Incorrect 5 ms 6632 KB Output isn't correct
9 Incorrect 5 ms 6632 KB Output isn't correct
10 Incorrect 4 ms 6632 KB Output isn't correct
11 Incorrect 4 ms 6632 KB Output isn't correct
12 Incorrect 4 ms 6632 KB Output isn't correct
13 Incorrect 4 ms 6632 KB Output isn't correct
14 Incorrect 5 ms 6632 KB Output isn't correct
15 Incorrect 4 ms 6632 KB Output isn't correct
16 Incorrect 4 ms 6632 KB Output isn't correct
17 Incorrect 4 ms 6632 KB Output isn't correct
18 Incorrect 4 ms 6632 KB Output isn't correct
19 Incorrect 3 ms 6632 KB Output isn't correct
20 Incorrect 4 ms 6632 KB Output isn't correct