답안 #118061

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118061 2019-06-18T05:28:01 Z 김세빈(#2888) Lamps (JOI19_lamps) C++14
6 / 100
88 ms 2304 KB
#include <bits/stdc++.h>

using namespace std;

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

int f()
{
	int i;
	
	dp[0][0] = 0; dp[0][1] = 1e9; dp[0][2] = 1e9;
	
	for(i=0; i<n; i++){
		if(A[i] != B[i]) dp[1][0] = 1e9;
		else dp[1][0] = min({dp[0][0], dp[0][1], dp[0][2]});
		
		dp[1][1] = dp[0][0] + 1;
		if(i && B[i - 1] != B[i]) dp[1][1] = min(dp[1][1], min(dp[0][1] + 1, dp[0][2]));
		else dp[1][1] = min(dp[1][1], min(dp[0][1], dp[0][2] + 1));
		
		dp[1][2] = dp[0][0] + 2;
		if(i && B[i - 1] != B[i]) dp[1][2] = min(dp[1][2], min(dp[0][1] + 1, dp[0][2] + 2));
		else dp[1][2] = min(dp[1][2], min(dp[0][1] + 2, dp[0][2]));
		
		dp[0][0] = dp[1][0]; dp[0][1] = dp[1][1]; dp[0][2] = dp[1][2];
	}
	
	return min({dp[0][0], dp[0][1], dp[0][2]});
}

int main()
{
	int i, j, k;
	
	scanf("%d%s%s", &n, A, B);
	
	ans = n;
	
	if(n > 18) return 0;
	
	for(i=0; i<(1<<n); i++){
		if(i & 1) k = 1;
		else k = 0;
		
		for(j=0; j<n; j++){
			if(i & (1 << j)) B[j] = (int)'0' + '1' - B[j];
			if(j && (!(i & (1 << j - 1)) && (i & (1 << j)))) k ++;
		}
		
		ans = min(ans, f() + k);
		
		for(j=0; j<n; j++){
			if(i & (1 << j)) B[j] = (int)'0' + '1' - B[j];
		}
	}
	
	printf("%d\n", ans);
	
	return 0;
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:49:27: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
    if(j && (!(i & (1 << j - 1)) && (i & (1 << j)))) k ++;
                         ~~^~~
lamp.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%s%s", &n, A, B);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 88 ms 384 KB Output is correct
9 Correct 64 ms 256 KB Output is correct
10 Correct 32 ms 384 KB Output is correct
11 Correct 31 ms 256 KB Output is correct
12 Correct 64 ms 384 KB Output is correct
13 Correct 32 ms 400 KB Output is correct
14 Correct 68 ms 384 KB Output is correct
15 Correct 33 ms 256 KB Output is correct
16 Correct 67 ms 376 KB Output is correct
17 Correct 33 ms 256 KB Output is correct
18 Correct 66 ms 376 KB Output is correct
19 Correct 33 ms 376 KB Output is correct
20 Correct 67 ms 368 KB Output is correct
21 Correct 32 ms 256 KB Output is correct
22 Correct 65 ms 384 KB Output is correct
23 Correct 32 ms 384 KB Output is correct
24 Correct 65 ms 376 KB Output is correct
25 Correct 33 ms 376 KB Output is correct
26 Correct 65 ms 404 KB Output is correct
27 Correct 32 ms 404 KB Output is correct
28 Correct 17 ms 384 KB Output is correct
29 Correct 66 ms 384 KB Output is correct
30 Correct 32 ms 384 KB Output is correct
31 Correct 17 ms 256 KB Output is correct
32 Correct 65 ms 368 KB Output is correct
33 Correct 32 ms 384 KB Output is correct
34 Correct 18 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 88 ms 384 KB Output is correct
9 Correct 64 ms 256 KB Output is correct
10 Correct 32 ms 384 KB Output is correct
11 Correct 31 ms 256 KB Output is correct
12 Correct 64 ms 384 KB Output is correct
13 Correct 32 ms 400 KB Output is correct
14 Correct 68 ms 384 KB Output is correct
15 Correct 33 ms 256 KB Output is correct
16 Correct 67 ms 376 KB Output is correct
17 Correct 33 ms 256 KB Output is correct
18 Correct 66 ms 376 KB Output is correct
19 Correct 33 ms 376 KB Output is correct
20 Correct 67 ms 368 KB Output is correct
21 Correct 32 ms 256 KB Output is correct
22 Correct 65 ms 384 KB Output is correct
23 Correct 32 ms 384 KB Output is correct
24 Correct 65 ms 376 KB Output is correct
25 Correct 33 ms 376 KB Output is correct
26 Correct 65 ms 404 KB Output is correct
27 Correct 32 ms 404 KB Output is correct
28 Correct 17 ms 384 KB Output is correct
29 Correct 66 ms 384 KB Output is correct
30 Correct 32 ms 384 KB Output is correct
31 Correct 17 ms 256 KB Output is correct
32 Correct 65 ms 368 KB Output is correct
33 Correct 32 ms 384 KB Output is correct
34 Correct 18 ms 384 KB Output is correct
35 Incorrect 2 ms 384 KB Output isn't correct
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 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 384 KB Output is correct
7 Incorrect 9 ms 2304 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 88 ms 384 KB Output is correct
9 Correct 64 ms 256 KB Output is correct
10 Correct 32 ms 384 KB Output is correct
11 Correct 31 ms 256 KB Output is correct
12 Correct 64 ms 384 KB Output is correct
13 Correct 32 ms 400 KB Output is correct
14 Correct 68 ms 384 KB Output is correct
15 Correct 33 ms 256 KB Output is correct
16 Correct 67 ms 376 KB Output is correct
17 Correct 33 ms 256 KB Output is correct
18 Correct 66 ms 376 KB Output is correct
19 Correct 33 ms 376 KB Output is correct
20 Correct 67 ms 368 KB Output is correct
21 Correct 32 ms 256 KB Output is correct
22 Correct 65 ms 384 KB Output is correct
23 Correct 32 ms 384 KB Output is correct
24 Correct 65 ms 376 KB Output is correct
25 Correct 33 ms 376 KB Output is correct
26 Correct 65 ms 404 KB Output is correct
27 Correct 32 ms 404 KB Output is correct
28 Correct 17 ms 384 KB Output is correct
29 Correct 66 ms 384 KB Output is correct
30 Correct 32 ms 384 KB Output is correct
31 Correct 17 ms 256 KB Output is correct
32 Correct 65 ms 368 KB Output is correct
33 Correct 32 ms 384 KB Output is correct
34 Correct 18 ms 384 KB Output is correct
35 Incorrect 2 ms 384 KB Output isn't correct
36 Halted 0 ms 0 KB -