답안 #260072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
260072 2020-08-09T08:32:14 Z arnold518 Vim (BOI13_vim) C++14
55 / 100
1008 ms 99576 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 5000;

int N;
char A[MAXN+10];
int dp[MAXN+10][MAXN+10];
vector<int> V[10];

vector<int>::iterator low[MAXN+10][10], upp[MAXN+10][10];

int solve(int now, int pos)
{
	int &ret=dp[now][pos];
	if(ret!=-1) return ret;
	ret=1e9;

	for(int i=0; i<10; i++)
	{
		if(i==4) continue;
		auto it=upp[now][i];
		if(it==V[i].end()) continue;
		ret=min(ret, solve(*it, pos)+2);
	}
	if(now>pos)
	{
		int p=now-pos+low[now][4]-low[pos][4];
		auto jt=upp[now][4];
		if(jt==V[4].end()) ret=min(ret, p);
		else
		{
			for(int i=0; i<10; i++)
			{
				if(i==4) continue;
				auto it=upp[pos+1][i];
				if(it==V[i].end()) continue;
				ret=min(ret, solve(*it, *jt)+p+2);
			}
		}
	}
	//printf("%d %d : %d\n", now, pos, ret);
	return ret;
}

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

	for(int i=1; i<=N; i++) V[A[i]-'a'].push_back(i);
	for(int j=0; j<10; j++) for(int i=1; i<=N; i++) low[i][j]=lower_bound(V[j].begin(), V[j].end(), i);
	for(int j=0; j<10; j++) for(int i=1; i<=N; i++) upp[i][j]=upper_bound(V[j].begin(), V[j].end(), i);

	if(V[4].empty()) return !printf("0\n");
	memset(dp, -1, sizeof(dp));
	printf("%d\n", solve(1, V[4].front()));
}

Compilation message

vim.cpp: In function 'int main()':
vim.cpp:52:17: warning: too many arguments for format [-Wformat-extra-args]
  scanf("%*d", &N);
                 ^
vim.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%*d", &N);
  ~~~~~^~~~~~~~~~~
vim.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf(" %s", A+1);
  ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 98680 KB Output is correct
2 Correct 55 ms 98680 KB Output is correct
3 Correct 53 ms 98680 KB Output is correct
4 Correct 57 ms 98796 KB Output is correct
5 Correct 55 ms 98680 KB Output is correct
6 Correct 57 ms 98700 KB Output is correct
7 Correct 56 ms 98680 KB Output is correct
8 Correct 51 ms 98516 KB Output is correct
9 Correct 51 ms 98556 KB Output is correct
10 Correct 50 ms 98552 KB Output is correct
11 Correct 50 ms 98552 KB Output is correct
12 Correct 51 ms 98552 KB Output is correct
13 Correct 54 ms 98680 KB Output is correct
14 Correct 54 ms 98680 KB Output is correct
15 Correct 53 ms 98680 KB Output is correct
16 Correct 53 ms 98680 KB Output is correct
17 Correct 56 ms 98680 KB Output is correct
18 Correct 55 ms 98684 KB Output is correct
19 Correct 53 ms 98680 KB Output is correct
20 Correct 54 ms 98576 KB Output is correct
21 Correct 56 ms 98680 KB Output is correct
22 Correct 55 ms 98680 KB Output is correct
23 Correct 54 ms 98680 KB Output is correct
24 Correct 54 ms 98680 KB Output is correct
25 Correct 54 ms 98680 KB Output is correct
26 Correct 55 ms 98624 KB Output is correct
27 Correct 57 ms 98680 KB Output is correct
28 Correct 58 ms 98680 KB Output is correct
29 Correct 59 ms 98808 KB Output is correct
30 Correct 55 ms 98680 KB Output is correct
31 Correct 60 ms 98680 KB Output is correct
32 Correct 56 ms 98680 KB Output is correct
33 Correct 55 ms 98680 KB Output is correct
34 Correct 56 ms 98680 KB Output is correct
35 Correct 56 ms 98680 KB Output is correct
36 Correct 58 ms 98684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 499 ms 99448 KB Output isn't correct
2 Correct 999 ms 99468 KB Output is correct
3 Incorrect 242 ms 99192 KB Output isn't correct
4 Incorrect 499 ms 99448 KB Output isn't correct
5 Correct 1006 ms 99576 KB Output is correct
6 Correct 882 ms 99528 KB Output is correct
7 Incorrect 605 ms 99576 KB Output isn't correct
8 Incorrect 615 ms 99448 KB Output isn't correct
9 Correct 1008 ms 99576 KB Output is correct
10 Correct 944 ms 99528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 5 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 6 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 6 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 6 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 6 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 5 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 5 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)