Submission #251940

# Submission time Handle Problem Language Result Execution time Memory
251940 2020-07-23T07:52:57 Z nnnnnnnnnnnnnnnn Lamps (JOI19_lamps) C++14
4 / 100
137 ms 18292 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
const int N = 1e6,inf = 1e8;
int n;
string a,b;
int dp[4][N];	
// ->0
// ->1
// flip
int solve()
{
	int i,j,k;
	for(i=0;i<4;i++)
	{
		for(j=0;j<n;j++)
		{
			dp[i][j] = inf;
		}
	}
	if(a[0]==b[0])
	{
		if(a[0]=='0')	dp[0][0] = 1;
		else			dp[1][0] = 1;
		dp[3][0] = 0;
	}
	else
	{
		dp[2][0] = 1;
		if(b[0]=='0')	dp[0][0] = 1;
		else			dp[1][0] = 1;
	}
	for(i=1;i<n;i++)
	{
		for(j=0;j<4;j++)
		{
			for(k=0;k<4;k++)
			{
				dp[j][i] = min(dp[j][i],dp[k][i-1]+1);
			}
		}
		if(a[i]==b[i])
		{
			dp[2][i] = inf;
			for(j=0;j<4;j++)
			{
				dp[3][i] = min(dp[3][i],dp[j][i-1]);
			}
			if(a[i]=='0')
			{
				dp[0][i] = min(dp[0][i],dp[0][i-1]);
				dp[1][i] = inf;
			}
			else
			{
				dp[1][i] = min(dp[1][i],dp[1][i-1]);
				dp[0][i] = inf;
			}
		}
		else
		{
			dp[3][i] = inf;
			if(a[i]=='0')
			{
				dp[0][i] = inf;
				dp[2][i] = min(dp[2][i],dp[2][i-1]);
				dp[1][i] = min(dp[1][i],dp[1][i-1]);
			}
			else
			{
				dp[1][i] = inf;
				dp[2][i] = min(dp[2][i],dp[2][i-1]);
				dp[0][i] = min(dp[0][i],dp[0][i-1]);
			}
		}
	}
/*	for(i=0;i<4;i++)
	{
		for(j=0;j<n;j++)
		{
			if(dp[i][j]==inf)	printf("! ");
			else
			printf("%d ",dp[i][j]);
		}
		printf("\n");
	}			*/
	int ans = min(min(dp[0][n-1],dp[1][n-1]),min(dp[2][n-1],dp[3][n-1]));
	return ans;
}
int main()
{
	scanf("%d",&n);
	cin >> a >> b;
	int res = solve();
	printf("%d",res);
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:97:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Incorrect 1 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Incorrect 1 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 127 ms 18136 KB Output is correct
8 Correct 137 ms 18024 KB Output is correct
9 Correct 124 ms 18156 KB Output is correct
10 Correct 126 ms 18024 KB Output is correct
11 Correct 126 ms 18024 KB Output is correct
12 Correct 121 ms 18020 KB Output is correct
13 Correct 128 ms 18028 KB Output is correct
14 Correct 135 ms 18292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Incorrect 1 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -