Submission #126403

# Submission time Handle Problem Language Result Execution time Memory
126403 2019-07-07T15:38:26 Z TadijaSebez Lamps (JOI19_lamps) C++11
4 / 100
31 ms 22008 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][5];
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;
	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][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][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]);
	ans=min(ans,dp[n][4]);
	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 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 Incorrect 2 ms 276 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 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 Incorrect 2 ms 276 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 256 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 30 ms 22008 KB Output is correct
8 Correct 30 ms 21884 KB Output is correct
9 Correct 30 ms 21880 KB Output is correct
10 Correct 30 ms 21880 KB Output is correct
11 Correct 30 ms 21880 KB Output is correct
12 Correct 31 ms 21880 KB Output is correct
13 Correct 30 ms 21852 KB Output is correct
14 Correct 30 ms 21880 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 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 Incorrect 2 ms 276 KB Output isn't correct
17 Halted 0 ms 0 KB -