Submission #126400

# Submission time Handle Problem Language Result Execution time Memory
126400 2019-07-07T15:32:00 Z TadijaSebez Lamps (JOI19_lamps) C++11
4 / 100
30 ms 17912 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][4];
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;
	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][0]=inf;
		}
		else
		{
			dp[i][1]=inf;
			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][2]=min(dp[i-1][2]+(b[i]!=b[i-1]),dp[i-1][0]+1);
		dp[i][3]=min(dp[i-1][3]+(b[i]!=b[i-1]),dp[i-1][1]+1);
	}
	int ans=min(dp[n][0],dp[n][1]);
	ans=min(ans,dp[n][2]);
	ans=min(ans,dp[n][3]);
	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 256 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 256 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 380 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 Incorrect 2 ms 376 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 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 256 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 380 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 Incorrect 2 ms 376 KB Output isn't correct
17 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 26 ms 17912 KB Output is correct
8 Correct 27 ms 17912 KB Output is correct
9 Correct 27 ms 17912 KB Output is correct
10 Correct 30 ms 17912 KB Output is correct
11 Correct 27 ms 17912 KB Output is correct
12 Correct 30 ms 17912 KB Output is correct
13 Correct 26 ms 17912 KB Output is correct
14 Correct 26 ms 17912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 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 256 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 380 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 Incorrect 2 ms 376 KB Output isn't correct
17 Halted 0 ms 0 KB -