Submission #260084

# Submission time Handle Problem Language Result Execution time Memory
260084 2020-08-09T09:09:24 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(pos==V[4].front() && now>=4000) printf("HIHIIHI %d %d %d\n", now, i, *it);
	}
	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:53:17: warning: too many arguments for format [-Wformat-extra-args]
  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("%*d", &N);
  ~~~~~^~~~~~~~~~~
vim.cpp:54: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 54 ms 98680 KB Output is correct
2 Correct 58 ms 98668 KB Output is correct
3 Correct 55 ms 98680 KB Output is correct
4 Correct 62 ms 98680 KB Output is correct
5 Correct 55 ms 98680 KB Output is correct
6 Correct 57 ms 98680 KB Output is correct
7 Correct 59 ms 98664 KB Output is correct
8 Correct 51 ms 98552 KB Output is correct
9 Correct 50 ms 98552 KB Output is correct
10 Correct 51 ms 98556 KB Output is correct
11 Correct 50 ms 98552 KB Output is correct
12 Correct 51 ms 98552 KB Output is correct
13 Correct 57 ms 98680 KB Output is correct
14 Correct 54 ms 98624 KB Output is correct
15 Correct 52 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 54 ms 98680 KB Output is correct
19 Correct 53 ms 98680 KB Output is correct
20 Correct 53 ms 98680 KB Output is correct
21 Correct 61 ms 98680 KB Output is correct
22 Correct 68 ms 98680 KB Output is correct
23 Correct 59 ms 98716 KB Output is correct
24 Correct 54 ms 98680 KB Output is correct
25 Correct 54 ms 98680 KB Output is correct
26 Correct 59 ms 98680 KB Output is correct
27 Correct 56 ms 98680 KB Output is correct
28 Correct 59 ms 98680 KB Output is correct
29 Correct 58 ms 98808 KB Output is correct
30 Correct 55 ms 98680 KB Output is correct
31 Correct 54 ms 98608 KB Output is correct
32 Correct 55 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 57 ms 98832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 497 ms 99448 KB Output isn't correct
2 Correct 980 ms 99576 KB Output is correct
3 Incorrect 221 ms 99064 KB Output isn't correct
4 Incorrect 496 ms 99576 KB Output isn't correct
5 Correct 957 ms 99508 KB Output is correct
6 Correct 833 ms 99488 KB Output is correct
7 Incorrect 603 ms 99500 KB Output isn't correct
8 Incorrect 616 ms 99448 KB Output isn't correct
9 Correct 1008 ms 99472 KB Output is correct
10 Correct 977 ms 99448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 6 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 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 5 ms 544 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 6 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 6 ms 512 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 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 6 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 5 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 512 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 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)