Submission #895872

# Submission time Handle Problem Language Result Execution time Memory
895872 2023-12-31T02:38:10 Z noompty Vim (BOI13_vim) C++17
100 / 100
27 ms 36744 KB
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=7e4,alpha='k'-'a'+1;
int n,len,cnte,f[maxn+1][alpha],g[maxn+1][alpha][alpha];
bool key[maxn+2];
char s[maxn+3];
int main()
{
	memset(f,0x3f,sizeof f);
	memset(g,0x3f,sizeof g);
	scanf("%d\n",&n);
	for(int i=1,check=0;i<=n;++i)
	{
		char t=getchar();
		if(t=='e')
			check=++cnte;
		else
		{
			key[++len]=check;
			s[len]=t-'a';
			check=0;
		}
	}
	f[0][s[1]]=0;
	for(int i=1;i<=len;++i)
		for(int j=0;j<alpha;++j)
		{
			if(j!=s[i])
			{
				if(!key[i])
					f[i][j]=f[i-1][j];
				f[i][j]=min(f[i][j],g[i-1][s[i]][j]);
			}
			f[i][j]=min(f[i][j],min(f[i-1][s[i]],g[i-1][s[i]][s[i]])+2);
			for(int k=0;k<alpha;++k)
			{
				if(j!=s[i]&&k!=s[i])
					g[i][j][k]=g[i-1][j][k]+1;
				if(j!=s[i])
					g[i][j][k]=min(g[i][j][k],min(f[i-1][j],g[i-1][j][s[i]])+3);
				if(k!=s[i])
					g[i][j][k]=min(g[i][j][k],g[i-1][s[i]][k]+3);
				g[i][j][k]=min(g[i][j][k],min(g[i-1][s[i]][s[i]]+5,f[i-1][s[i]]+5));
			}
		}
	printf("%d",f[len][alpha-1]+(cnte<<1)-2);
	return 0;
} 

Compilation message

vim.cpp: In function 'int main()':
vim.cpp:26:10: warning: array subscript has type 'char' [-Wchar-subscripts]
   26 |  f[0][s[1]]=0;
      |       ~~~^
vim.cpp:34:35: warning: array subscript has type 'char' [-Wchar-subscripts]
   34 |     f[i][j]=min(f[i][j],g[i-1][s[i]][j]);
      |                                ~~~^
vim.cpp:36:38: warning: array subscript has type 'char' [-Wchar-subscripts]
   36 |    f[i][j]=min(f[i][j],min(f[i-1][s[i]],g[i-1][s[i]][s[i]])+2);
      |                                   ~~~^
vim.cpp:36:51: warning: array subscript has type 'char' [-Wchar-subscripts]
   36 |    f[i][j]=min(f[i][j],min(f[i-1][s[i]],g[i-1][s[i]][s[i]])+2);
      |                                                ~~~^
vim.cpp:36:57: warning: array subscript has type 'char' [-Wchar-subscripts]
   36 |    f[i][j]=min(f[i][j],min(f[i-1][s[i]],g[i-1][s[i]][s[i]])+2);
      |                                                      ~~~^
vim.cpp:42:59: warning: array subscript has type 'char' [-Wchar-subscripts]
   42 |      g[i][j][k]=min(g[i][j][k],min(f[i-1][j],g[i-1][j][s[i]])+3);
      |                                                        ~~~^
vim.cpp:44:42: warning: array subscript has type 'char' [-Wchar-subscripts]
   44 |      g[i][j][k]=min(g[i][j][k],g[i-1][s[i]][k]+3);
      |                                       ~~~^
vim.cpp:45:45: warning: array subscript has type 'char' [-Wchar-subscripts]
   45 |     g[i][j][k]=min(g[i][j][k],min(g[i-1][s[i]][s[i]]+5,f[i-1][s[i]]+5));
      |                                          ~~~^
vim.cpp:45:51: warning: array subscript has type 'char' [-Wchar-subscripts]
   45 |     g[i][j][k]=min(g[i][j][k],min(g[i-1][s[i]][s[i]]+5,f[i-1][s[i]]+5));
      |                                                ~~~^
vim.cpp:45:66: warning: array subscript has type 'char' [-Wchar-subscripts]
   45 |     g[i][j][k]=min(g[i][j][k],min(g[i-1][s[i]][s[i]]+5,f[i-1][s[i]]+5));
      |                                                               ~~~^
vim.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  scanf("%d\n",&n);
      |  ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 36444 KB Output is correct
2 Correct 6 ms 36548 KB Output is correct
3 Correct 5 ms 36440 KB Output is correct
4 Correct 6 ms 36444 KB Output is correct
5 Correct 5 ms 36440 KB Output is correct
6 Correct 5 ms 36576 KB Output is correct
7 Correct 5 ms 36444 KB Output is correct
8 Correct 5 ms 36444 KB Output is correct
9 Correct 5 ms 36444 KB Output is correct
10 Correct 5 ms 36444 KB Output is correct
11 Correct 5 ms 36440 KB Output is correct
12 Correct 5 ms 36444 KB Output is correct
13 Correct 6 ms 36444 KB Output is correct
14 Correct 5 ms 36444 KB Output is correct
15 Correct 5 ms 36444 KB Output is correct
16 Correct 5 ms 36444 KB Output is correct
17 Correct 5 ms 36444 KB Output is correct
18 Correct 5 ms 36444 KB Output is correct
19 Correct 5 ms 36440 KB Output is correct
20 Correct 5 ms 36552 KB Output is correct
21 Correct 5 ms 36696 KB Output is correct
22 Correct 5 ms 36440 KB Output is correct
23 Correct 5 ms 36444 KB Output is correct
24 Correct 5 ms 36580 KB Output is correct
25 Correct 5 ms 36444 KB Output is correct
26 Correct 5 ms 36444 KB Output is correct
27 Correct 5 ms 36444 KB Output is correct
28 Correct 5 ms 36440 KB Output is correct
29 Correct 5 ms 36440 KB Output is correct
30 Correct 5 ms 36444 KB Output is correct
31 Correct 5 ms 36552 KB Output is correct
32 Correct 6 ms 36444 KB Output is correct
33 Correct 5 ms 36444 KB Output is correct
34 Correct 5 ms 36440 KB Output is correct
35 Correct 5 ms 36444 KB Output is correct
36 Correct 5 ms 36444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 36444 KB Output is correct
2 Correct 6 ms 36444 KB Output is correct
3 Correct 7 ms 36700 KB Output is correct
4 Correct 6 ms 36572 KB Output is correct
5 Correct 6 ms 36568 KB Output is correct
6 Correct 6 ms 36444 KB Output is correct
7 Correct 6 ms 36444 KB Output is correct
8 Correct 6 ms 36444 KB Output is correct
9 Correct 6 ms 36444 KB Output is correct
10 Correct 6 ms 36584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 36700 KB Output is correct
2 Correct 21 ms 36736 KB Output is correct
3 Correct 27 ms 36700 KB Output is correct
4 Correct 22 ms 36696 KB Output is correct
5 Correct 24 ms 36696 KB Output is correct
6 Correct 14 ms 36696 KB Output is correct
7 Correct 19 ms 36720 KB Output is correct
8 Correct 21 ms 36740 KB Output is correct
9 Correct 17 ms 36720 KB Output is correct
10 Correct 17 ms 36700 KB Output is correct
11 Correct 22 ms 36700 KB Output is correct
12 Correct 24 ms 36604 KB Output is correct
13 Correct 23 ms 36696 KB Output is correct
14 Correct 23 ms 36700 KB Output is correct
15 Correct 21 ms 36736 KB Output is correct
16 Correct 23 ms 36700 KB Output is correct
17 Correct 22 ms 36744 KB Output is correct
18 Correct 21 ms 36736 KB Output is correct
19 Correct 21 ms 36728 KB Output is correct
20 Correct 18 ms 36700 KB Output is correct