Submission #156276

# Submission time Handle Problem Language Result Execution time Memory
156276 2019-10-04T17:47:31 Z popovicirobert Lamps (JOI19_lamps) C++14
100 / 100
362 ms 67036 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lsb(x) (x & (-x)) 
    
using namespace std;

const int MAXN = (int) 1e6 + 5;

char A[MAXN + 1], B[MAXN + 1];

int dp[MAXN + 1][4][4];

int aux[2][4][4];
   
int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
		
	cin >> n >> A + 1 >> B + 1;

	for(i = 0; i <= n; i++) {
		A[i] -= '0', B[i] -= '0';
		for(int a = 0; a <= 3; a++) {
			for(int b = 0; b <= 3; b++) {
				dp[i][a][b] = MAXN;
			}
		}
	}

	auto get = [&](int x, int y) {
		if(y == 0) return x;
		if(y == 1) return 0;
		if(y == 2) return 1;
		return x ^ 1;
	};

	auto check = [&](int x, int y, int z) {
		return get(get(x, y), z);
	};

	for(i = 0; i < 2; i++) {
		for(int a = 0; a <= 3; a++) {
			for(int b = 0; b <= 3; b++) {
				aux[i][a][b] = check(i, a, b);
			}
		}
	}

	dp[0][0][0] = 0;

	for(i = 1; i <= n; i++) {
		for(int a = 0; a <= 3; a++) {
			for(int b = (a > 0); b <= 3; b++) {
				if(dp[i - 1][a][b] == MAXN) continue;

				for(int c = 0; c <= 3; c++) {
					for(int d = (c > 0); d <= 3; d++) {
						if(aux[A[i]][c][d] != B[i]) continue;

						int cnt = MAXN;
						if(a == c && b == d) {
							cnt = 0;
						}
						else {
							if(a == c || b == c) {
								cnt = min(cnt, (int)(d > 0));
							}
							if(a == d || b == d) {
								cnt = min(cnt, (int)(c > 0));
							}
							cnt = min(cnt, (c > 0) + (d > 0));
						}
						dp[i][c][d] = min(dp[i][c][d], dp[i - 1][a][b] + cnt);
					}
				}
			}
		}
	}

	int ans = MAXN;
	for(int a = 0; a <= 3; a++) {
		for(int b = (a > 0); b <= 3; b++) {
			if(check(A[n], a, b) == B[n])
				ans = min(ans, dp[n][a][b]);
		}
	}

	cout << ans;
            
	return 0;
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:23:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  cin >> n >> A + 1 >> B + 1;
              ~~^~~
lamp.cpp:23:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  cin >> n >> A + 1 >> B + 1;
                       ~~^~~
lamp.cpp:62:18: warning: array subscript has type 'char' [-Wchar-subscripts]
       if(aux[A[i]][c][d] != B[i]) continue;
                  ^
# 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 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 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 504 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 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 380 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 296 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
# 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 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 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 504 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 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 380 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 296 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 3 ms 504 KB Output is correct
36 Correct 3 ms 504 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 504 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 3 ms 504 KB Output is correct
43 Correct 3 ms 504 KB Output is correct
44 Correct 3 ms 504 KB Output is correct
45 Correct 3 ms 504 KB Output is correct
46 Correct 3 ms 504 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 3 ms 504 KB Output is correct
49 Correct 3 ms 504 KB Output is correct
50 Correct 3 ms 504 KB Output is correct
51 Correct 3 ms 504 KB Output is correct
52 Correct 3 ms 504 KB Output is correct
53 Correct 3 ms 504 KB Output is correct
54 Correct 3 ms 504 KB Output is correct
55 Correct 3 ms 512 KB Output is correct
56 Correct 3 ms 504 KB Output is correct
57 Correct 3 ms 504 KB Output is correct
58 Correct 3 ms 504 KB Output is correct
# 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 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 404 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 362 ms 66920 KB Output is correct
8 Correct 335 ms 66808 KB Output is correct
9 Correct 336 ms 66936 KB Output is correct
10 Correct 336 ms 66808 KB Output is correct
11 Correct 335 ms 66940 KB Output is correct
12 Correct 305 ms 66936 KB Output is correct
13 Correct 322 ms 66808 KB Output is correct
14 Correct 328 ms 66920 KB Output is correct
# 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 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 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 504 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 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 380 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 296 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 3 ms 504 KB Output is correct
36 Correct 3 ms 504 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 3 ms 504 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 3 ms 504 KB Output is correct
42 Correct 3 ms 504 KB Output is correct
43 Correct 3 ms 504 KB Output is correct
44 Correct 3 ms 504 KB Output is correct
45 Correct 3 ms 504 KB Output is correct
46 Correct 3 ms 504 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 3 ms 504 KB Output is correct
49 Correct 3 ms 504 KB Output is correct
50 Correct 3 ms 504 KB Output is correct
51 Correct 3 ms 504 KB Output is correct
52 Correct 3 ms 504 KB Output is correct
53 Correct 3 ms 504 KB Output is correct
54 Correct 3 ms 504 KB Output is correct
55 Correct 3 ms 512 KB Output is correct
56 Correct 3 ms 504 KB Output is correct
57 Correct 3 ms 504 KB Output is correct
58 Correct 3 ms 504 KB Output is correct
59 Correct 2 ms 376 KB Output is correct
60 Correct 2 ms 376 KB Output is correct
61 Correct 2 ms 376 KB Output is correct
62 Correct 2 ms 376 KB Output is correct
63 Correct 2 ms 404 KB Output is correct
64 Correct 2 ms 376 KB Output is correct
65 Correct 362 ms 66920 KB Output is correct
66 Correct 335 ms 66808 KB Output is correct
67 Correct 336 ms 66936 KB Output is correct
68 Correct 336 ms 66808 KB Output is correct
69 Correct 335 ms 66940 KB Output is correct
70 Correct 305 ms 66936 KB Output is correct
71 Correct 322 ms 66808 KB Output is correct
72 Correct 328 ms 66920 KB Output is correct
73 Correct 324 ms 66940 KB Output is correct
74 Correct 347 ms 66924 KB Output is correct
75 Correct 303 ms 66832 KB Output is correct
76 Correct 305 ms 66808 KB Output is correct
77 Correct 329 ms 66936 KB Output is correct
78 Correct 329 ms 66928 KB Output is correct
79 Correct 349 ms 66920 KB Output is correct
80 Correct 304 ms 67036 KB Output is correct
81 Correct 328 ms 66908 KB Output is correct
82 Correct 328 ms 66936 KB Output is correct
83 Correct 340 ms 66808 KB Output is correct
84 Correct 341 ms 66936 KB Output is correct
85 Correct 340 ms 66912 KB Output is correct
86 Correct 343 ms 66936 KB Output is correct
87 Correct 358 ms 66912 KB Output is correct
88 Correct 355 ms 66808 KB Output is correct
89 Correct 341 ms 66916 KB Output is correct
90 Correct 348 ms 66808 KB Output is correct
91 Correct 345 ms 66936 KB Output is correct
92 Correct 346 ms 67004 KB Output is correct
93 Correct 348 ms 66912 KB Output is correct
94 Correct 349 ms 66936 KB Output is correct
95 Correct 347 ms 66808 KB Output is correct
96 Correct 348 ms 66948 KB Output is correct
97 Correct 350 ms 66808 KB Output is correct
98 Correct 348 ms 66936 KB Output is correct
99 Correct 350 ms 66936 KB Output is correct
100 Correct 351 ms 66916 KB Output is correct
101 Correct 349 ms 66996 KB Output is correct
102 Correct 348 ms 66920 KB Output is correct