Submission #260069

# Submission time Handle Problem Language Result Execution time Memory
260069 2020-08-09T08:24:21 Z arnold518 Vim (BOI13_vim) C++14
50 / 100
2000 ms 98808 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[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+1);
				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);

	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:17: warning: too many arguments for format [-Wformat-extra-args]
  scanf("%*d", &N);
                 ^
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 61 ms 98556 KB Output is correct
2 Correct 61 ms 98552 KB Output is correct
3 Correct 56 ms 98680 KB Output is correct
4 Correct 63 ms 98552 KB Output is correct
5 Correct 62 ms 98584 KB Output is correct
6 Correct 71 ms 98552 KB Output is correct
7 Correct 67 ms 98552 KB Output is correct
8 Correct 52 ms 98684 KB Output is correct
9 Correct 50 ms 98552 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 60 ms 98556 KB Output is correct
14 Correct 61 ms 98552 KB Output is correct
15 Correct 56 ms 98552 KB Output is correct
16 Correct 61 ms 98552 KB Output is correct
17 Correct 66 ms 98552 KB Output is correct
18 Correct 60 ms 98552 KB Output is correct
19 Correct 60 ms 98552 KB Output is correct
20 Correct 59 ms 98552 KB Output is correct
21 Correct 64 ms 98552 KB Output is correct
22 Correct 62 ms 98552 KB Output is correct
23 Correct 61 ms 98552 KB Output is correct
24 Correct 63 ms 98552 KB Output is correct
25 Correct 61 ms 98496 KB Output is correct
26 Correct 70 ms 98680 KB Output is correct
27 Correct 71 ms 98528 KB Output is correct
28 Correct 78 ms 98552 KB Output is correct
29 Correct 69 ms 98556 KB Output is correct
30 Correct 62 ms 98552 KB Output is correct
31 Correct 61 ms 98552 KB Output is correct
32 Correct 63 ms 98552 KB Output is correct
33 Correct 63 ms 98552 KB Output is correct
34 Correct 65 ms 98552 KB Output is correct
35 Correct 65 ms 98552 KB Output is correct
36 Correct 67 ms 98552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1422 ms 98808 KB Output isn't correct
2 Execution timed out 2027 ms 98680 KB Time limit exceeded
3 Incorrect 562 ms 98636 KB Output isn't correct
4 Incorrect 1381 ms 98808 KB Output isn't correct
5 Execution timed out 2076 ms 98680 KB Time limit exceeded
6 Execution timed out 2102 ms 98808 KB Time limit exceeded
7 Incorrect 1829 ms 98704 KB Output isn't correct
8 Incorrect 1793 ms 98680 KB Output isn't correct
9 Execution timed out 2098 ms 98680 KB Time limit exceeded
10 Execution timed out 2043 ms 98684 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 5 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 6 ms 384 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 5 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 6 ms 384 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 428 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 6 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 6 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 7 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 5 ms 384 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 5 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 5 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 5 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 6 ms 384 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 6 ms 384 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)