Submission #126422

# Submission time Handle Problem Language Result Execution time Memory
126422 2019-07-07T17:04:53 Z TadijaSebez Lamps (JOI19_lamps) C++11
10 / 100
83 ms 61080 KB
#include <bits/stdc++.h>
using namespace std;
const int N=1000050;
const int inf=1e9+7;
int col[N][3][2][2];
int dp[N][3];
char a[N],b[N];
int main()
{
	int n;
	scanf("%i %s %s",&n,a+1,b+1);
	dp[0][0]=0;dp[0][1]=dp[0][2]=inf;
	for(int i=0;i<3;i++) for(int j=0;j<2;j++) for(int k=0;k<2;k++) col[0][i][j][k]=inf;
	for(int t=1;t<=n;t++)
	{
		for(int i=0;i<3;i++)
			for(int k=0;k<2;k++)
			{
				col[t][i][0][k]=inf;
				if(b[t]!=b[t-1])
				{
					if(i<3) col[t][i][1][k]=min(col[t-1][i][1][k^1]+(k==0),col[t-1][i][0][k^1]+(k==0));
					else col[t][i][1][k]=min(col[t-1][i][1][k^1]+(k==1),col[t-1][i][0][k^1]+(k==1));
				}
				else col[t][i][1][k]=col[t-1][i][1][k],col[t][i][0][k]=col[t-1][i][0][k];
			}
		col[t][0][0][1]=min(col[t][0][0][1],dp[t-1][0]+1);
		col[t][1][0][1]=min(col[t][1][0][1],dp[t-1][1]+1);
		col[t][1][0][1]=min(col[t][1][0][1],dp[t-1][2]+1);
		col[t][2][0][1]=min(col[t][2][0][1],dp[t-1][2]+1);
		col[t][2][0][1]=min(col[t][2][0][1],dp[t-1][1]+1);
		int A=inf,B=inf,C=inf;
		for(int j=0;j<2;j++) for(int k=0;k<2;k++)
		{
			A=min(A,col[t-1][0][j][k]);
			B=min(B,col[t-1][1][j][k]);
			C=min(C,col[t-1][2][j][k]);
		}
		if(a[t]!=b[t])
		{
			dp[t][0]=inf;
			dp[t][1]=min(A+1,min(B,C+1));
			dp[t][1]=min(dp[t][1],dp[t-1][0]+1);
			dp[t][1]=min(dp[t][1],dp[t-1][1]);
			dp[t][2]=min(col[t-1][0][1][0],min(col[t-1][1][1][0],col[t-1][2][1][1]));
			dp[t][2]=min(dp[t][2],dp[t-1][2]);
		}
		else
		{
			dp[t][0]=min(min(dp[t-1][0],min(dp[t-1][1],dp[t-1][2])),min(A,min(B,C)));
			dp[t][1]=inf;
			dp[t][2]=inf;
		}
	}
	int ans=min(dp[n][0],min(dp[n][1],dp[n][2]));
	for(int i=0;i<3;i++) for(int j=0;j<2;j++) for(int k=0;k<2;k++) ans=min(ans,col[n][i][j][k]);
	printf("%i\n",ans);
	return 0;
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %s %s",&n,a+1,b+1);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 424 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 380 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 424 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 380 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 504 KB Output is correct
36 Correct 2 ms 504 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 2 ms 504 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Incorrect 2 ms 504 KB Output isn't correct
41 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 72 ms 60920 KB Output is correct
8 Correct 73 ms 60920 KB Output is correct
9 Correct 81 ms 61080 KB Output is correct
10 Correct 83 ms 61048 KB Output is correct
11 Correct 83 ms 61048 KB Output is correct
12 Correct 74 ms 61048 KB Output is correct
13 Correct 74 ms 60940 KB Output is correct
14 Correct 74 ms 61048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 424 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 380 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 504 KB Output is correct
36 Correct 2 ms 504 KB Output is correct
37 Correct 2 ms 504 KB Output is correct
38 Correct 2 ms 504 KB Output is correct
39 Correct 2 ms 504 KB Output is correct
40 Incorrect 2 ms 504 KB Output isn't correct
41 Halted 0 ms 0 KB -