답안 #118059

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118059 2019-06-18T04:54:10 Z 김세빈(#2888) Lamps (JOI19_lamps) C++14
4 / 100
17 ms 4224 KB
#include <bits/stdc++.h>

using namespace std;

int dp[2][5];
char A[1010101], B[1010101];
int n;

int main()
{
	int i, j, t, f1, f2;
	
	scanf("%d%s%s", &n, A + 1, B + 1);
	
	A[0] = B[0] = '0';
	
	for(i=1; i<5; i++){
		dp[0][i] = 1e9;
	}
	
	for(i=1; i<=n; i++){
		t = (B[i - 1] != B[i]); f1 = (A[i - 1] != B[i - 1]); f2 = (A[i] != B[i]);
		
		dp[1][0] = min({dp[0][0] + (f1 ^ f2), dp[0][1] + ((B[i - 1] == '1') ^ f2), dp[0][2] + ((B[i - 1] == '0') ^ f2)});
		dp[1][1] = min({dp[0][0] + 1 + (f1 ^ (B[i] == '1')), dp[0][1] + t, dp[0][2] + 1 + !t, dp[0][3] + !t});
		dp[1][2] = min({dp[0][0] + 1 + (f1 ^ (B[i] == '0')), dp[0][1] + 1 + !t, dp[0][2] + t, dp[0][4] + !t});
		dp[1][3] = min(dp[0][1] + 1 + !t, dp[0][3] + t);
		dp[1][4] = min(dp[0][2] + 1 + !t, dp[0][4] + t);
		
		for(j=0; j<5; j++){
			dp[0][j] = dp[1][j];
		}
	}
	
	printf("%d\n", min({dp[0][0], dp[0][1], dp[0][2], dp[0][3], dp[0][4]}));
	
	return 0;
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%s%s", &n, A + 1, B + 1);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Incorrect 2 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Incorrect 2 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 17 ms 4224 KB Output is correct
8 Correct 17 ms 4224 KB Output is correct
9 Correct 16 ms 4224 KB Output is correct
10 Correct 17 ms 4224 KB Output is correct
11 Correct 17 ms 4224 KB Output is correct
12 Correct 17 ms 4224 KB Output is correct
13 Correct 17 ms 4224 KB Output is correct
14 Correct 17 ms 4224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Incorrect 2 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -