Submission #143625

# Submission time Handle Problem Language Result Execution time Memory
143625 2019-08-14T18:37:02 Z godwind Lamps (JOI19_lamps) C++14
100 / 100
104 ms 43540 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
//#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
                        
using namespace std;
                        
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
                        
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}
 
#define ghost signed
#define left left228
#define right right228
#define complex complex228
#define count count228
#define sin sin228
#define list list228

const int N = 1000 * 1000 + 228;
const int INF = 1e9 + 228;

int n;
int s[N], t[N];
int dp[N][3][2];
int color[N][3];
/*
0 - none
1 - color 0
2 - color 1
*/

ghost main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	cin >> n;
	char chaaa;
	for (int i = 1; i <= n; ++i) {
		cin >> chaaa;
		s[i] = (chaaa - '0');
	}
	for (int i = 1; i <= n; ++i) {
		cin >> chaaa;
		t[i] = (chaaa - '0');
	}
	for (int i = 1; i <= n; ++i) {
		color[i][0] = s[i];
		color[i][1] = 0;
		color[i][2] = 1;
	}
	for (int i = 1; i <= n; ++i) {
		for (int c1 = 0; c1 < 3; ++c1) {
			for (int c2 = 0; c2 < 2; ++c2) {
				dp[i][c1][c2] = INF;
			}
		}
	}
	for (int c1 = 0; c1 < 3; ++c1) {
		for (int c2 = 0; c2 < 2; ++c2) {
			if ((color[1][c1] ^ c2) == t[1]) {
				dp[1][c1][c2] = (c1 > 0) + (c2 > 0);
			}
		}
	}
	for (int i = 1; i < n; ++i) {
		for (int c1 = 0; c1 < 3; ++c1) {
			for (int c2 = 0; c2 < 2; ++c2) {
				if (dp[i][c1][c2] == INF) continue;
				for (int b1 = 0; b1 < 3; ++b1) {
					for (int b2 = 0; b2 < 2; ++b2) {
						if ((color[i + 1][b1] ^ b2) != t[i + 1]) continue;
						uin(dp[i + 1][b1][b2], dp[i][c1][c2] + (b1 && b1 != c1) + (b2 && b2 != c2));
					}
				}
			}
		}
	}
	int res = INF;
	for (int c1 = 0; c1 < 3; ++c1) {
		for (int c2 = 0; c2 < 2; ++c2) uin(res, dp[n][c1][c2]);
	}
	cout << res << '\n';
    return 0;
} // kek ;
// Ого! Кажетсья это $#@!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
# 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 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 504 KB Output is correct
12 Correct 2 ms 376 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 376 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 380 KB Output is correct
21 Correct 2 ms 376 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 376 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 2 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 504 KB Output is correct
12 Correct 2 ms 376 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 376 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 380 KB Output is correct
21 Correct 2 ms 376 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 376 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 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 504 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 504 KB Output is correct
44 Correct 2 ms 504 KB Output is correct
45 Correct 3 ms 504 KB Output is correct
46 Correct 2 ms 504 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 2 ms 504 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 504 KB Output is correct
51 Correct 2 ms 504 KB Output is correct
52 Correct 2 ms 504 KB Output is correct
53 Correct 2 ms 376 KB Output is correct
54 Correct 2 ms 504 KB Output is correct
55 Correct 2 ms 380 KB Output is correct
56 Correct 2 ms 504 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 2 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 380 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 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 90 ms 43512 KB Output is correct
8 Correct 96 ms 43332 KB Output is correct
9 Correct 98 ms 43376 KB Output is correct
10 Correct 89 ms 43384 KB Output is correct
11 Correct 92 ms 43388 KB Output is correct
12 Correct 89 ms 43384 KB Output is correct
13 Correct 90 ms 43384 KB Output is correct
14 Correct 91 ms 43384 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 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 504 KB Output is correct
12 Correct 2 ms 376 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 376 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 380 KB Output is correct
21 Correct 2 ms 376 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 376 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 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 504 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 504 KB Output is correct
44 Correct 2 ms 504 KB Output is correct
45 Correct 3 ms 504 KB Output is correct
46 Correct 2 ms 504 KB Output is correct
47 Correct 3 ms 504 KB Output is correct
48 Correct 2 ms 504 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 504 KB Output is correct
51 Correct 2 ms 504 KB Output is correct
52 Correct 2 ms 504 KB Output is correct
53 Correct 2 ms 376 KB Output is correct
54 Correct 2 ms 504 KB Output is correct
55 Correct 2 ms 380 KB Output is correct
56 Correct 2 ms 504 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 2 ms 504 KB Output is correct
59 Correct 2 ms 376 KB Output is correct
60 Correct 2 ms 380 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 376 KB Output is correct
64 Correct 2 ms 376 KB Output is correct
65 Correct 90 ms 43512 KB Output is correct
66 Correct 96 ms 43332 KB Output is correct
67 Correct 98 ms 43376 KB Output is correct
68 Correct 89 ms 43384 KB Output is correct
69 Correct 92 ms 43388 KB Output is correct
70 Correct 89 ms 43384 KB Output is correct
71 Correct 90 ms 43384 KB Output is correct
72 Correct 91 ms 43384 KB Output is correct
73 Correct 97 ms 43392 KB Output is correct
74 Correct 90 ms 43384 KB Output is correct
75 Correct 92 ms 43444 KB Output is correct
76 Correct 90 ms 43384 KB Output is correct
77 Correct 99 ms 43476 KB Output is correct
78 Correct 91 ms 43384 KB Output is correct
79 Correct 90 ms 43384 KB Output is correct
80 Correct 92 ms 43512 KB Output is correct
81 Correct 93 ms 43388 KB Output is correct
82 Correct 93 ms 43384 KB Output is correct
83 Correct 104 ms 43440 KB Output is correct
84 Correct 102 ms 43444 KB Output is correct
85 Correct 96 ms 43384 KB Output is correct
86 Correct 97 ms 43384 KB Output is correct
87 Correct 98 ms 43384 KB Output is correct
88 Correct 97 ms 43384 KB Output is correct
89 Correct 96 ms 43472 KB Output is correct
90 Correct 97 ms 43384 KB Output is correct
91 Correct 101 ms 43384 KB Output is correct
92 Correct 102 ms 43384 KB Output is correct
93 Correct 103 ms 43384 KB Output is correct
94 Correct 103 ms 43384 KB Output is correct
95 Correct 102 ms 43512 KB Output is correct
96 Correct 103 ms 43384 KB Output is correct
97 Correct 102 ms 43384 KB Output is correct
98 Correct 103 ms 43540 KB Output is correct
99 Correct 102 ms 43384 KB Output is correct
100 Correct 102 ms 43384 KB Output is correct
101 Correct 103 ms 43384 KB Output is correct
102 Correct 103 ms 43384 KB Output is correct