Submission #129168

# Submission time Handle Problem Language Result Execution time Memory
129168 2019-07-11T18:41:24 Z Mahmoud_Adel Lamps (JOI19_lamps) C++14
100 / 100
271 ms 90188 KB
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
const int N = 1e6+5;
int n, dp[N][5], nxt[N];
string a, b;
void operate()
{
	int one = n, zero = n;
	for(int i=n-1; i>=0; i--)
	{
		if(b[i] == '1') one = i, nxt[i] = zero;
		else zero = i, nxt[i] = one;
	}
}
int sol(int i, int t)
{
	if(i == n) return 0;
	int &ret = dp[i][t];
	if(ret != -1) return ret;
	ret = sol(nxt[i], t)+1;
	if(t == 2 && nxt[i] != n)
	{
		if(b[i] == '0') ret = min(ret, sol(nxt[i], 1)+1);
		else ret = min(ret, sol(nxt[i], 0)+1);
	}
	if((t == 1 && b[i] == '0') || (t == 0 && b[i] == '1'))
		ret = min(ret, sol(nxt[i], 2)+1);
	if(t == 3)
	{
		if(a[i] == b[i]) ret = min(ret, sol(i+1, t));
		else if(b[i] == '0') ret = min(ret, min(sol(i+1, 2), sol(i+1, 0))+1);
		else ret = min(ret, min(sol(i+1, 2), sol(i+1, 1))+1);
	}
	if(t == 2)
	{
		if(a[i] == b[i]) ret = min(ret, sol(i+1, 3));
		else ret = min(ret, sol(i+1, t));
	}
	if(t == 1)
	{
		if(b[i] == '1') ret = min(ret, sol(i+1, t));
		else if(b[i] == a[i]) ret = min(ret, sol(i+1, 3));
		else ret = min(ret, min(sol(i+1, 2), sol(i+1, 0))+1);
	}
	if(!t)
	{
		if(b[i] == '0') ret = min(ret, sol(i+1, t));
		else if(a[i] == b[i]) ret = min(ret, sol(i+1, 3));
		else ret = min(ret, min(sol(i+1, 2), sol(i+1, 1))+1);
	}
	return ret;
}
int main()
{
	memset(dp, -1, sizeof dp);
	cin >> n >> a >> b;
	operate();
	cout << sol(0, 3) << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 19836 KB Output is correct
2 Correct 18 ms 19832 KB Output is correct
3 Correct 18 ms 19832 KB Output is correct
4 Correct 18 ms 19832 KB Output is correct
5 Correct 22 ms 19960 KB Output is correct
6 Correct 19 ms 19832 KB Output is correct
7 Correct 18 ms 19832 KB Output is correct
8 Correct 18 ms 19832 KB Output is correct
9 Correct 18 ms 19832 KB Output is correct
10 Correct 18 ms 19960 KB Output is correct
11 Correct 18 ms 20088 KB Output is correct
12 Correct 18 ms 19836 KB Output is correct
13 Correct 18 ms 19960 KB Output is correct
14 Correct 18 ms 19832 KB Output is correct
15 Correct 18 ms 19832 KB Output is correct
16 Correct 18 ms 19832 KB Output is correct
17 Correct 18 ms 19832 KB Output is correct
18 Correct 18 ms 19836 KB Output is correct
19 Correct 18 ms 19832 KB Output is correct
20 Correct 18 ms 19960 KB Output is correct
21 Correct 18 ms 19960 KB Output is correct
22 Correct 18 ms 19960 KB Output is correct
23 Correct 18 ms 19832 KB Output is correct
24 Correct 18 ms 19960 KB Output is correct
25 Correct 18 ms 19832 KB Output is correct
26 Correct 18 ms 19832 KB Output is correct
27 Correct 18 ms 19960 KB Output is correct
28 Correct 18 ms 19832 KB Output is correct
29 Correct 18 ms 20004 KB Output is correct
30 Correct 19 ms 19960 KB Output is correct
31 Correct 18 ms 19832 KB Output is correct
32 Correct 18 ms 19932 KB Output is correct
33 Correct 18 ms 19832 KB Output is correct
34 Correct 18 ms 19832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 19836 KB Output is correct
2 Correct 18 ms 19832 KB Output is correct
3 Correct 18 ms 19832 KB Output is correct
4 Correct 18 ms 19832 KB Output is correct
5 Correct 22 ms 19960 KB Output is correct
6 Correct 19 ms 19832 KB Output is correct
7 Correct 18 ms 19832 KB Output is correct
8 Correct 18 ms 19832 KB Output is correct
9 Correct 18 ms 19832 KB Output is correct
10 Correct 18 ms 19960 KB Output is correct
11 Correct 18 ms 20088 KB Output is correct
12 Correct 18 ms 19836 KB Output is correct
13 Correct 18 ms 19960 KB Output is correct
14 Correct 18 ms 19832 KB Output is correct
15 Correct 18 ms 19832 KB Output is correct
16 Correct 18 ms 19832 KB Output is correct
17 Correct 18 ms 19832 KB Output is correct
18 Correct 18 ms 19836 KB Output is correct
19 Correct 18 ms 19832 KB Output is correct
20 Correct 18 ms 19960 KB Output is correct
21 Correct 18 ms 19960 KB Output is correct
22 Correct 18 ms 19960 KB Output is correct
23 Correct 18 ms 19832 KB Output is correct
24 Correct 18 ms 19960 KB Output is correct
25 Correct 18 ms 19832 KB Output is correct
26 Correct 18 ms 19832 KB Output is correct
27 Correct 18 ms 19960 KB Output is correct
28 Correct 18 ms 19832 KB Output is correct
29 Correct 18 ms 20004 KB Output is correct
30 Correct 19 ms 19960 KB Output is correct
31 Correct 18 ms 19832 KB Output is correct
32 Correct 18 ms 19932 KB Output is correct
33 Correct 18 ms 19832 KB Output is correct
34 Correct 18 ms 19832 KB Output is correct
35 Correct 18 ms 19960 KB Output is correct
36 Correct 18 ms 19960 KB Output is correct
37 Correct 19 ms 20088 KB Output is correct
38 Correct 18 ms 19980 KB Output is correct
39 Correct 19 ms 19960 KB Output is correct
40 Correct 19 ms 19964 KB Output is correct
41 Correct 18 ms 19960 KB Output is correct
42 Correct 19 ms 19960 KB Output is correct
43 Correct 19 ms 19900 KB Output is correct
44 Correct 20 ms 19960 KB Output is correct
45 Correct 18 ms 19960 KB Output is correct
46 Correct 18 ms 19960 KB Output is correct
47 Correct 19 ms 19960 KB Output is correct
48 Correct 18 ms 19960 KB Output is correct
49 Correct 19 ms 19964 KB Output is correct
50 Correct 18 ms 19960 KB Output is correct
51 Correct 18 ms 19960 KB Output is correct
52 Correct 18 ms 19960 KB Output is correct
53 Correct 19 ms 19932 KB Output is correct
54 Correct 18 ms 19912 KB Output is correct
55 Correct 18 ms 19960 KB Output is correct
56 Correct 18 ms 19960 KB Output is correct
57 Correct 19 ms 19960 KB Output is correct
58 Correct 19 ms 19960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 19960 KB Output is correct
2 Correct 18 ms 19832 KB Output is correct
3 Correct 18 ms 19960 KB Output is correct
4 Correct 18 ms 19960 KB Output is correct
5 Correct 18 ms 19960 KB Output is correct
6 Correct 18 ms 19960 KB Output is correct
7 Correct 212 ms 90188 KB Output is correct
8 Correct 266 ms 90124 KB Output is correct
9 Correct 264 ms 89956 KB Output is correct
10 Correct 270 ms 90028 KB Output is correct
11 Correct 267 ms 90084 KB Output is correct
12 Correct 264 ms 89960 KB Output is correct
13 Correct 180 ms 29156 KB Output is correct
14 Correct 184 ms 28924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 19836 KB Output is correct
2 Correct 18 ms 19832 KB Output is correct
3 Correct 18 ms 19832 KB Output is correct
4 Correct 18 ms 19832 KB Output is correct
5 Correct 22 ms 19960 KB Output is correct
6 Correct 19 ms 19832 KB Output is correct
7 Correct 18 ms 19832 KB Output is correct
8 Correct 18 ms 19832 KB Output is correct
9 Correct 18 ms 19832 KB Output is correct
10 Correct 18 ms 19960 KB Output is correct
11 Correct 18 ms 20088 KB Output is correct
12 Correct 18 ms 19836 KB Output is correct
13 Correct 18 ms 19960 KB Output is correct
14 Correct 18 ms 19832 KB Output is correct
15 Correct 18 ms 19832 KB Output is correct
16 Correct 18 ms 19832 KB Output is correct
17 Correct 18 ms 19832 KB Output is correct
18 Correct 18 ms 19836 KB Output is correct
19 Correct 18 ms 19832 KB Output is correct
20 Correct 18 ms 19960 KB Output is correct
21 Correct 18 ms 19960 KB Output is correct
22 Correct 18 ms 19960 KB Output is correct
23 Correct 18 ms 19832 KB Output is correct
24 Correct 18 ms 19960 KB Output is correct
25 Correct 18 ms 19832 KB Output is correct
26 Correct 18 ms 19832 KB Output is correct
27 Correct 18 ms 19960 KB Output is correct
28 Correct 18 ms 19832 KB Output is correct
29 Correct 18 ms 20004 KB Output is correct
30 Correct 19 ms 19960 KB Output is correct
31 Correct 18 ms 19832 KB Output is correct
32 Correct 18 ms 19932 KB Output is correct
33 Correct 18 ms 19832 KB Output is correct
34 Correct 18 ms 19832 KB Output is correct
35 Correct 18 ms 19960 KB Output is correct
36 Correct 18 ms 19960 KB Output is correct
37 Correct 19 ms 20088 KB Output is correct
38 Correct 18 ms 19980 KB Output is correct
39 Correct 19 ms 19960 KB Output is correct
40 Correct 19 ms 19964 KB Output is correct
41 Correct 18 ms 19960 KB Output is correct
42 Correct 19 ms 19960 KB Output is correct
43 Correct 19 ms 19900 KB Output is correct
44 Correct 20 ms 19960 KB Output is correct
45 Correct 18 ms 19960 KB Output is correct
46 Correct 18 ms 19960 KB Output is correct
47 Correct 19 ms 19960 KB Output is correct
48 Correct 18 ms 19960 KB Output is correct
49 Correct 19 ms 19964 KB Output is correct
50 Correct 18 ms 19960 KB Output is correct
51 Correct 18 ms 19960 KB Output is correct
52 Correct 18 ms 19960 KB Output is correct
53 Correct 19 ms 19932 KB Output is correct
54 Correct 18 ms 19912 KB Output is correct
55 Correct 18 ms 19960 KB Output is correct
56 Correct 18 ms 19960 KB Output is correct
57 Correct 19 ms 19960 KB Output is correct
58 Correct 19 ms 19960 KB Output is correct
59 Correct 18 ms 19960 KB Output is correct
60 Correct 18 ms 19832 KB Output is correct
61 Correct 18 ms 19960 KB Output is correct
62 Correct 18 ms 19960 KB Output is correct
63 Correct 18 ms 19960 KB Output is correct
64 Correct 18 ms 19960 KB Output is correct
65 Correct 212 ms 90188 KB Output is correct
66 Correct 266 ms 90124 KB Output is correct
67 Correct 264 ms 89956 KB Output is correct
68 Correct 270 ms 90028 KB Output is correct
69 Correct 267 ms 90084 KB Output is correct
70 Correct 264 ms 89960 KB Output is correct
71 Correct 180 ms 29156 KB Output is correct
72 Correct 184 ms 28924 KB Output is correct
73 Correct 239 ms 89824 KB Output is correct
74 Correct 214 ms 89828 KB Output is correct
75 Correct 269 ms 89888 KB Output is correct
76 Correct 271 ms 89956 KB Output is correct
77 Correct 264 ms 89824 KB Output is correct
78 Correct 265 ms 89960 KB Output is correct
79 Correct 225 ms 89984 KB Output is correct
80 Correct 269 ms 89832 KB Output is correct
81 Correct 266 ms 89992 KB Output is correct
82 Correct 265 ms 89828 KB Output is correct
83 Correct 181 ms 27364 KB Output is correct
84 Correct 180 ms 27364 KB Output is correct
85 Correct 181 ms 27364 KB Output is correct
86 Correct 181 ms 27364 KB Output is correct
87 Correct 186 ms 28512 KB Output is correct
88 Correct 190 ms 28584 KB Output is correct
89 Correct 185 ms 28516 KB Output is correct
90 Correct 191 ms 28544 KB Output is correct
91 Correct 211 ms 42852 KB Output is correct
92 Correct 234 ms 52044 KB Output is correct
93 Correct 245 ms 58596 KB Output is correct
94 Correct 244 ms 58468 KB Output is correct
95 Correct 244 ms 58468 KB Output is correct
96 Correct 261 ms 58468 KB Output is correct
97 Correct 244 ms 58704 KB Output is correct
98 Correct 243 ms 58468 KB Output is correct
99 Correct 244 ms 58568 KB Output is correct
100 Correct 243 ms 58644 KB Output is correct
101 Correct 244 ms 58596 KB Output is correct
102 Correct 243 ms 58652 KB Output is correct