Submission #260068

# Submission time Handle Problem Language Result Execution time Memory
260068 2020-08-09T08:19:43 Z arnold518 Vim (BOI13_vim) C++14
13.8889 / 100
21 ms 4480 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 = 1000;

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

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

	for(int i=0; i<10; i++)
	{
		if(i==4) continue;
		auto it=upper_bound(V[i].begin(), V[i].end(), now);
		if(it==V[i].end()) continue;
		ret=min(ret, solve(*it, pos)+2);
	}
	if(now>pos)
	{
		int p=now-pos+lower_bound(V[4].begin(), V[4].end(), now)-lower_bound(V[4].begin(), V[4].end(), pos);
		auto jt=upper_bound(V[4].begin(), V[4].end(), now);
		if(jt==V[4].end()) ret=min(ret, p);
		else
		{
			for(int i=0; i<10; i++)
			{
				if(i==4) continue;
				auto it=upper_bound(V[i].begin(), V[i].end(), pos);
				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);

	for(int i=1; i<=N; i++) V[A[i]-'a'].push_back(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:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
vim.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf(" %s", A+1);
  ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4352 KB Output is correct
2 Incorrect 13 ms 4480 KB Output isn't correct
3 Incorrect 8 ms 4352 KB Output isn't correct
4 Incorrect 17 ms 4352 KB Output isn't correct
5 Correct 16 ms 4352 KB Output is correct
6 Incorrect 21 ms 4352 KB Output isn't correct
7 Incorrect 20 ms 4352 KB Output isn't correct
8 Correct 3 ms 4480 KB Output is correct
9 Correct 3 ms 4352 KB Output is correct
10 Incorrect 3 ms 4352 KB Output isn't correct
11 Correct 3 ms 4352 KB Output is correct
12 Correct 3 ms 4352 KB Output is correct
13 Correct 12 ms 4352 KB Output is correct
14 Incorrect 13 ms 4352 KB Output isn't correct
15 Incorrect 8 ms 4352 KB Output isn't correct
16 Incorrect 13 ms 4352 KB Output isn't correct
17 Incorrect 17 ms 4352 KB Output isn't correct
18 Incorrect 13 ms 4352 KB Output isn't correct
19 Correct 9 ms 4352 KB Output is correct
20 Correct 11 ms 4352 KB Output is correct
21 Incorrect 15 ms 4352 KB Output isn't correct
22 Correct 14 ms 4352 KB Output is correct
23 Incorrect 12 ms 4352 KB Output isn't correct
24 Incorrect 12 ms 4352 KB Output isn't correct
25 Incorrect 13 ms 4352 KB Output isn't correct
26 Incorrect 14 ms 4352 KB Output isn't correct
27 Incorrect 18 ms 4288 KB Output isn't correct
28 Incorrect 21 ms 4352 KB Output isn't correct
29 Incorrect 20 ms 4352 KB Output isn't correct
30 Incorrect 14 ms 4352 KB Output isn't correct
31 Incorrect 13 ms 4352 KB Output isn't correct
32 Incorrect 15 ms 4352 KB Output isn't correct
33 Incorrect 15 ms 4352 KB Output isn't correct
34 Incorrect 17 ms 4352 KB Output isn't correct
35 Incorrect 17 ms 4352 KB Output isn't correct
36 Incorrect 20 ms 4472 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 3 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 1 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 3 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 3 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 2 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 2 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 2 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)