답안 #251943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251943 2020-07-23T08:16:40 Z nnnnnnnnnnnnnnnn Lamps (JOI19_lamps) C++14
4 / 100
154 ms 18152 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();
	for(int i=0;i<n;i++)
	{
		if(b[i]=='0')	b[i]='1';
		else			b[i]='0';
	}
	res = min(res,solve()+1);
	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);
  ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 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 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 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 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Incorrect 0 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 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 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Incorrect 0 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 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 154 ms 18024 KB Output is correct
8 Correct 151 ms 18028 KB Output is correct
9 Correct 149 ms 18024 KB Output is correct
10 Correct 152 ms 18076 KB Output is correct
11 Correct 150 ms 18028 KB Output is correct
12 Correct 150 ms 18020 KB Output is correct
13 Correct 149 ms 18152 KB Output is correct
14 Correct 149 ms 18024 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 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 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Incorrect 0 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -