답안 #425278

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
425278 2021-06-12T18:46:03 Z songc Vim (BOI13_vim) C++14
23.6111 / 100
32 ms 34068 KB
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define Mup(a,x) a=max(a, x)
#define mup(a,x) a=min(a, x)
#define all(v) v.begin(),v.end()
#define lb lower_bound
#define INF (1ll<<60)
#define MOD 1'000'000'007 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int M, N, X, sum, ans=MOD;
int A[70707], D[70707][11][11];
bool E[70707];

int main(){
	char c;
	bool tf = false;
	scanf("%d", &M);
	for (int i=0; i<M; i++){
		scanf(" %c", &c);
		if (c != 'e'){
			A[++N] = c-'a'+1+(c<'e'?1:0);
			if (tf) X = N;
			E[N] = tf, tf = false;
		}
		else tf = true, sum += 2;
	}
	if (!X){puts("0"); return 0;}
	memset(D, 1, sizeof D);
	for (int i=2; i<=10; i++) D[1][i][0] = 2;
	for (int i=1; i<N; i++){
		for (int j=2; j<=10; j++){
			if (A[i+1] == j){
				if (i+1>=X) ans = min(ans, min(D[i][j][0], D[i][j][1]));
				for (int k=2; k<=10; k++) D[i+1][k][0] = min(D[i+1][k][0], D[i][j][0]+2);
			}
			else{
				if (!E[i+1]) D[i+1][j][0] = min(D[i+1][j][0], D[i][j][0]);
				D[i+1][j][1] = min(D[i+1][j][1], min(D[i][j][0], D[i][j][1])+1);
				for (int k=2; k<=10; k++) D[i+1][j][k] = min(D[i+1][j][k], D[i][j][0]+3);
			}
			for (int k=2; k<=10; k++){
				if (A[i+1] == k) continue;
				if (A[i+1] == j) D[i+1][k][0] = min(D[i+1][k][0], D[i][j][k]);
				else D[i+1][j][k] = min(D[i+1][j][k], D[i][j][k]+1);
			}
		}
	}
	printf("%d\n", ans+sum);
	return 0;
}

Compilation message

vim.cpp: In function 'int main()':
vim.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  scanf("%d", &M);
      |  ~~~~~^~~~~~~~~~
vim.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   scanf(" %c", &c);
      |   ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 33700 KB Output is correct
2 Incorrect 15 ms 33700 KB Output isn't correct
3 Incorrect 15 ms 33700 KB Output isn't correct
4 Incorrect 14 ms 33776 KB Output isn't correct
5 Correct 15 ms 33740 KB Output is correct
6 Incorrect 18 ms 33728 KB Output isn't correct
7 Incorrect 15 ms 33768 KB Output isn't correct
8 Correct 16 ms 33740 KB Output is correct
9 Correct 15 ms 33724 KB Output is correct
10 Correct 14 ms 33708 KB Output is correct
11 Correct 14 ms 33796 KB Output is correct
12 Correct 14 ms 33700 KB Output is correct
13 Correct 14 ms 33796 KB Output is correct
14 Incorrect 15 ms 33740 KB Output isn't correct
15 Incorrect 16 ms 33780 KB Output isn't correct
16 Incorrect 15 ms 33716 KB Output isn't correct
17 Correct 15 ms 33708 KB Output is correct
18 Incorrect 15 ms 33732 KB Output isn't correct
19 Incorrect 17 ms 33696 KB Output isn't correct
20 Correct 15 ms 33740 KB Output is correct
21 Incorrect 18 ms 33840 KB Output isn't correct
22 Correct 15 ms 33740 KB Output is correct
23 Incorrect 15 ms 33700 KB Output isn't correct
24 Incorrect 15 ms 33740 KB Output isn't correct
25 Correct 15 ms 33740 KB Output is correct
26 Correct 15 ms 33736 KB Output is correct
27 Correct 15 ms 33680 KB Output is correct
28 Incorrect 15 ms 33728 KB Output isn't correct
29 Incorrect 15 ms 33720 KB Output isn't correct
30 Incorrect 15 ms 33740 KB Output isn't correct
31 Correct 15 ms 33716 KB Output is correct
32 Incorrect 15 ms 33736 KB Output isn't correct
33 Correct 15 ms 33720 KB Output is correct
34 Correct 15 ms 33684 KB Output is correct
35 Incorrect 15 ms 33720 KB Output isn't correct
36 Incorrect 15 ms 33728 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 33696 KB Output isn't correct
2 Incorrect 16 ms 33812 KB Output isn't correct
3 Incorrect 15 ms 33744 KB Output isn't correct
4 Incorrect 16 ms 33688 KB Output isn't correct
5 Incorrect 15 ms 33792 KB Output isn't correct
6 Incorrect 16 ms 33888 KB Output isn't correct
7 Incorrect 16 ms 33740 KB Output isn't correct
8 Incorrect 15 ms 33740 KB Output isn't correct
9 Incorrect 16 ms 33756 KB Output isn't correct
10 Incorrect 16 ms 33816 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 30 ms 33952 KB Output isn't correct
2 Incorrect 29 ms 33996 KB Output isn't correct
3 Incorrect 29 ms 34064 KB Output isn't correct
4 Incorrect 31 ms 33996 KB Output isn't correct
5 Incorrect 32 ms 34064 KB Output isn't correct
6 Incorrect 25 ms 33872 KB Output isn't correct
7 Incorrect 29 ms 33996 KB Output isn't correct
8 Incorrect 32 ms 33996 KB Output isn't correct
9 Incorrect 27 ms 33940 KB Output isn't correct
10 Incorrect 27 ms 33940 KB Output isn't correct
11 Incorrect 32 ms 34068 KB Output isn't correct
12 Incorrect 32 ms 33996 KB Output isn't correct
13 Incorrect 31 ms 33988 KB Output isn't correct
14 Incorrect 31 ms 33988 KB Output isn't correct
15 Incorrect 32 ms 33984 KB Output isn't correct
16 Incorrect 30 ms 34064 KB Output isn't correct
17 Incorrect 30 ms 34008 KB Output isn't correct
18 Incorrect 30 ms 33948 KB Output isn't correct
19 Incorrect 29 ms 34036 KB Output isn't correct
20 Incorrect 27 ms 33996 KB Output isn't correct