답안 #554636

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
554636 2022-04-29T02:12:20 Z pavement Lamps (JOI19_lamps) C++17
100 / 100
228 ms 121764 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
//#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using db = double;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using iiii = tuple<int, int, int, int>;
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

int N, mem[1000005][3][2];
bool A[1000005], B[1000005];
char C;

int dp(int n, int a, bool b) {
	if (n == N + 1) return (a == 2 ? 0 : 1e9);
	if (mem[n][a][b] != -1) return mem[n][a][b];
	int ret = 1e9;
	bool x = A[n];
	if (a != 2) x = a;
	for (int k = 0; k < 3; k++)
		ret = min(ret, dp(n + 1, k, x != B[n]) + ((k != a) && k != 2));
	mem[n][a][b] = ret + ((x != B[n]) && !b);
	return mem[n][a][b];
}

main() {
	memset(mem, -1, sizeof mem);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> C;
		A[i] = C == '1';
	}
	for (int i = 1; i <= N; i++) {
		cin >> C;
		B[i] = C == '1';
	}
	cout << min({dp(1, 0, 0) + 1, dp(1, 1, 0) + 1, dp(1, 2, 0)}) << '\n';
}

Compilation message

lamp.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 10 ms 23764 KB Output is correct
3 Correct 12 ms 23720 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 10 ms 23728 KB Output is correct
6 Correct 9 ms 23764 KB Output is correct
7 Correct 9 ms 23764 KB Output is correct
8 Correct 9 ms 23808 KB Output is correct
9 Correct 9 ms 23728 KB Output is correct
10 Correct 10 ms 23812 KB Output is correct
11 Correct 10 ms 23760 KB Output is correct
12 Correct 10 ms 23764 KB Output is correct
13 Correct 11 ms 23736 KB Output is correct
14 Correct 10 ms 23764 KB Output is correct
15 Correct 10 ms 23764 KB Output is correct
16 Correct 10 ms 23796 KB Output is correct
17 Correct 10 ms 23764 KB Output is correct
18 Correct 10 ms 23776 KB Output is correct
19 Correct 11 ms 23764 KB Output is correct
20 Correct 10 ms 23808 KB Output is correct
21 Correct 10 ms 23764 KB Output is correct
22 Correct 11 ms 23780 KB Output is correct
23 Correct 11 ms 23724 KB Output is correct
24 Correct 9 ms 23764 KB Output is correct
25 Correct 11 ms 23740 KB Output is correct
26 Correct 10 ms 23804 KB Output is correct
27 Correct 10 ms 23764 KB Output is correct
28 Correct 10 ms 23764 KB Output is correct
29 Correct 12 ms 23764 KB Output is correct
30 Correct 10 ms 23764 KB Output is correct
31 Correct 11 ms 23764 KB Output is correct
32 Correct 10 ms 23768 KB Output is correct
33 Correct 11 ms 23764 KB Output is correct
34 Correct 10 ms 23700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 10 ms 23764 KB Output is correct
3 Correct 12 ms 23720 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 10 ms 23728 KB Output is correct
6 Correct 9 ms 23764 KB Output is correct
7 Correct 9 ms 23764 KB Output is correct
8 Correct 9 ms 23808 KB Output is correct
9 Correct 9 ms 23728 KB Output is correct
10 Correct 10 ms 23812 KB Output is correct
11 Correct 10 ms 23760 KB Output is correct
12 Correct 10 ms 23764 KB Output is correct
13 Correct 11 ms 23736 KB Output is correct
14 Correct 10 ms 23764 KB Output is correct
15 Correct 10 ms 23764 KB Output is correct
16 Correct 10 ms 23796 KB Output is correct
17 Correct 10 ms 23764 KB Output is correct
18 Correct 10 ms 23776 KB Output is correct
19 Correct 11 ms 23764 KB Output is correct
20 Correct 10 ms 23808 KB Output is correct
21 Correct 10 ms 23764 KB Output is correct
22 Correct 11 ms 23780 KB Output is correct
23 Correct 11 ms 23724 KB Output is correct
24 Correct 9 ms 23764 KB Output is correct
25 Correct 11 ms 23740 KB Output is correct
26 Correct 10 ms 23804 KB Output is correct
27 Correct 10 ms 23764 KB Output is correct
28 Correct 10 ms 23764 KB Output is correct
29 Correct 12 ms 23764 KB Output is correct
30 Correct 10 ms 23764 KB Output is correct
31 Correct 11 ms 23764 KB Output is correct
32 Correct 10 ms 23768 KB Output is correct
33 Correct 11 ms 23764 KB Output is correct
34 Correct 10 ms 23700 KB Output is correct
35 Correct 10 ms 23896 KB Output is correct
36 Correct 10 ms 23892 KB Output is correct
37 Correct 11 ms 23972 KB Output is correct
38 Correct 10 ms 23892 KB Output is correct
39 Correct 9 ms 23892 KB Output is correct
40 Correct 11 ms 23892 KB Output is correct
41 Correct 11 ms 24012 KB Output is correct
42 Correct 11 ms 23940 KB Output is correct
43 Correct 11 ms 23896 KB Output is correct
44 Correct 10 ms 23892 KB Output is correct
45 Correct 13 ms 24020 KB Output is correct
46 Correct 13 ms 23896 KB Output is correct
47 Correct 10 ms 23936 KB Output is correct
48 Correct 11 ms 23892 KB Output is correct
49 Correct 10 ms 24008 KB Output is correct
50 Correct 10 ms 24012 KB Output is correct
51 Correct 10 ms 23892 KB Output is correct
52 Correct 11 ms 23892 KB Output is correct
53 Correct 10 ms 24020 KB Output is correct
54 Correct 10 ms 23972 KB Output is correct
55 Correct 10 ms 23892 KB Output is correct
56 Correct 10 ms 23944 KB Output is correct
57 Correct 10 ms 23892 KB Output is correct
58 Correct 14 ms 23952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 9 ms 23764 KB Output is correct
3 Correct 10 ms 23740 KB Output is correct
4 Correct 10 ms 23812 KB Output is correct
5 Correct 10 ms 23720 KB Output is correct
6 Correct 9 ms 23764 KB Output is correct
7 Correct 190 ms 119736 KB Output is correct
8 Correct 195 ms 121636 KB Output is correct
9 Correct 191 ms 121748 KB Output is correct
10 Correct 190 ms 121736 KB Output is correct
11 Correct 193 ms 121556 KB Output is correct
12 Correct 202 ms 121640 KB Output is correct
13 Correct 189 ms 121572 KB Output is correct
14 Correct 228 ms 121720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 10 ms 23764 KB Output is correct
3 Correct 12 ms 23720 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 10 ms 23728 KB Output is correct
6 Correct 9 ms 23764 KB Output is correct
7 Correct 9 ms 23764 KB Output is correct
8 Correct 9 ms 23808 KB Output is correct
9 Correct 9 ms 23728 KB Output is correct
10 Correct 10 ms 23812 KB Output is correct
11 Correct 10 ms 23760 KB Output is correct
12 Correct 10 ms 23764 KB Output is correct
13 Correct 11 ms 23736 KB Output is correct
14 Correct 10 ms 23764 KB Output is correct
15 Correct 10 ms 23764 KB Output is correct
16 Correct 10 ms 23796 KB Output is correct
17 Correct 10 ms 23764 KB Output is correct
18 Correct 10 ms 23776 KB Output is correct
19 Correct 11 ms 23764 KB Output is correct
20 Correct 10 ms 23808 KB Output is correct
21 Correct 10 ms 23764 KB Output is correct
22 Correct 11 ms 23780 KB Output is correct
23 Correct 11 ms 23724 KB Output is correct
24 Correct 9 ms 23764 KB Output is correct
25 Correct 11 ms 23740 KB Output is correct
26 Correct 10 ms 23804 KB Output is correct
27 Correct 10 ms 23764 KB Output is correct
28 Correct 10 ms 23764 KB Output is correct
29 Correct 12 ms 23764 KB Output is correct
30 Correct 10 ms 23764 KB Output is correct
31 Correct 11 ms 23764 KB Output is correct
32 Correct 10 ms 23768 KB Output is correct
33 Correct 11 ms 23764 KB Output is correct
34 Correct 10 ms 23700 KB Output is correct
35 Correct 10 ms 23896 KB Output is correct
36 Correct 10 ms 23892 KB Output is correct
37 Correct 11 ms 23972 KB Output is correct
38 Correct 10 ms 23892 KB Output is correct
39 Correct 9 ms 23892 KB Output is correct
40 Correct 11 ms 23892 KB Output is correct
41 Correct 11 ms 24012 KB Output is correct
42 Correct 11 ms 23940 KB Output is correct
43 Correct 11 ms 23896 KB Output is correct
44 Correct 10 ms 23892 KB Output is correct
45 Correct 13 ms 24020 KB Output is correct
46 Correct 13 ms 23896 KB Output is correct
47 Correct 10 ms 23936 KB Output is correct
48 Correct 11 ms 23892 KB Output is correct
49 Correct 10 ms 24008 KB Output is correct
50 Correct 10 ms 24012 KB Output is correct
51 Correct 10 ms 23892 KB Output is correct
52 Correct 11 ms 23892 KB Output is correct
53 Correct 10 ms 24020 KB Output is correct
54 Correct 10 ms 23972 KB Output is correct
55 Correct 10 ms 23892 KB Output is correct
56 Correct 10 ms 23944 KB Output is correct
57 Correct 10 ms 23892 KB Output is correct
58 Correct 14 ms 23952 KB Output is correct
59 Correct 10 ms 23764 KB Output is correct
60 Correct 9 ms 23764 KB Output is correct
61 Correct 10 ms 23740 KB Output is correct
62 Correct 10 ms 23812 KB Output is correct
63 Correct 10 ms 23720 KB Output is correct
64 Correct 9 ms 23764 KB Output is correct
65 Correct 190 ms 119736 KB Output is correct
66 Correct 195 ms 121636 KB Output is correct
67 Correct 191 ms 121748 KB Output is correct
68 Correct 190 ms 121736 KB Output is correct
69 Correct 193 ms 121556 KB Output is correct
70 Correct 202 ms 121640 KB Output is correct
71 Correct 189 ms 121572 KB Output is correct
72 Correct 228 ms 121720 KB Output is correct
73 Correct 186 ms 121580 KB Output is correct
74 Correct 192 ms 121572 KB Output is correct
75 Correct 201 ms 121552 KB Output is correct
76 Correct 193 ms 121552 KB Output is correct
77 Correct 194 ms 121536 KB Output is correct
78 Correct 197 ms 121764 KB Output is correct
79 Correct 184 ms 121584 KB Output is correct
80 Correct 206 ms 121636 KB Output is correct
81 Correct 202 ms 121744 KB Output is correct
82 Correct 186 ms 121548 KB Output is correct
83 Correct 198 ms 121644 KB Output is correct
84 Correct 220 ms 121676 KB Output is correct
85 Correct 196 ms 121548 KB Output is correct
86 Correct 186 ms 121640 KB Output is correct
87 Correct 193 ms 121620 KB Output is correct
88 Correct 187 ms 121548 KB Output is correct
89 Correct 184 ms 121648 KB Output is correct
90 Correct 184 ms 121644 KB Output is correct
91 Correct 181 ms 121640 KB Output is correct
92 Correct 187 ms 121560 KB Output is correct
93 Correct 184 ms 121648 KB Output is correct
94 Correct 186 ms 121756 KB Output is correct
95 Correct 192 ms 121600 KB Output is correct
96 Correct 187 ms 121564 KB Output is correct
97 Correct 183 ms 121528 KB Output is correct
98 Correct 188 ms 121676 KB Output is correct
99 Correct 184 ms 121636 KB Output is correct
100 Correct 189 ms 121548 KB Output is correct
101 Correct 191 ms 121572 KB Output is correct
102 Correct 187 ms 121568 KB Output is correct