Submission #126410

# Submission time Handle Problem Language Result Execution time Memory
126410 2019-07-07T15:47:52 Z TadijaSebez Lamps (JOI19_lamps) C++11
4 / 100
38 ms 29816 KB
#include <bits/stdc++.h>
using namespace std;
const int N=1000050;
const int inf=1e9+7;
char a[N],b[N];
int dp[N][7];
int main()
{
	int n;
	scanf("%i",&n);
	scanf("%s",a+1);
	scanf("%s",b+1);
	dp[0][0]=0;
	dp[0][1]=inf;
	dp[0][2]=inf;
	dp[0][3]=inf;
	dp[0][4]=inf;
	dp[0][5]=inf;
	dp[0][6]=inf;
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=b[i])
		{
			dp[i][1]=min(dp[i-1][1],dp[i-1][0]+1);
			dp[i][1]=min(dp[i][1],dp[i-1][3]);
			dp[i][1]=min(dp[i][1],dp[i-1][2]+1);
			dp[i][1]=min(dp[i][1],dp[i-1][6]);
			dp[i][1]=min(dp[i][1],dp[i-1][5]+1);
			dp[i][1]=min(dp[i][1],dp[i-1][4]);
			dp[i][0]=inf;
			dp[i][4]=inf;
		}
		else
		{
			dp[i][1]=inf;
			dp[i][4]=min(dp[i-1][1]+1,dp[i-1][0]+2);
			dp[i][4]=min(dp[i][4],dp[i-1][4]);
			dp[i][0]=min(dp[i-1][1],dp[i-1][0]);
			dp[i][0]=min(dp[i][0],dp[i-1][2]);
			dp[i][0]=min(dp[i][0],dp[i-1][3]);
			dp[i][0]=min(dp[i][0],dp[i-1][5]);
			dp[i][0]=min(dp[i][0],dp[i-1][6]);
		}
		if(b[i]!=b[i-1])
		{
			dp[i][2]=min(dp[i-1][5],dp[i-1][0]+1);
			dp[i][3]=min(dp[i-1][6],dp[i-1][1]+1);
			dp[i][5]=dp[i-1][2]+1;
			dp[i][6]=dp[i-1][3]+1;
		}
		else
		{
			dp[i][2]=min(dp[i-1][2],dp[i-1][0]+1);
			dp[i][3]=min(dp[i-1][3],dp[i-1][1]+1);
			dp[i][5]=dp[i-1][5];
			dp[i][6]=dp[i-1][6];
		}
	}
	int ans=min(dp[n][0],dp[n][1]);
	ans=min(ans,dp[n][2]);
	ans=min(ans,dp[n][3]);
	ans=min(ans,dp[n][4]);
	ans=min(ans,dp[n][5]);
	ans=min(ans,dp[n][6]);
	printf("%i\n",ans);
	return 0;
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
lamp.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",a+1);
  ~~~~~^~~~~~~~~~
lamp.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",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 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 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 380 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 376 KB Output is correct
26 Incorrect 2 ms 376 KB Output isn't correct
27 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 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 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 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 380 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 376 KB Output is correct
26 Incorrect 2 ms 376 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 348 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 37 ms 29740 KB Output is correct
8 Correct 38 ms 29688 KB Output is correct
9 Correct 37 ms 29688 KB Output is correct
10 Correct 37 ms 29816 KB Output is correct
11 Correct 37 ms 29816 KB Output is correct
12 Correct 37 ms 29796 KB Output is correct
13 Correct 37 ms 29688 KB Output is correct
14 Correct 37 ms 29688 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 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 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 380 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 376 KB Output is correct
26 Incorrect 2 ms 376 KB Output isn't correct
27 Halted 0 ms 0 KB -