Submission #390563

# Submission time Handle Problem Language Result Execution time Memory
390563 2021-04-16T10:17:28 Z peijar Lamps (JOI19_lamps) C++17
100 / 100
106 ms 51496 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int MAXN = 1e6+1;

int dp[MAXN][2][3];

signed main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int nbCarac;
	cin >> nbCarac;
	string have, want;
	cin >> have >> want;
	vector<bool> from(nbCarac), to(nbCarac);
	for (int iCarac(0); iCarac < nbCarac; ++iCarac)
		from[iCarac] = have[iCarac] - '0', to[iCarac] = want[iCarac] - '0';

	for (int i(0); i < MAXN; ++i)
		for (int j(0); j < 2; ++j)
			for (int k(0); k < 3; ++k)
				dp[i][j][k] = 1e9;
	dp[0][0][2] = 0;
	
	for (int nbVus(1); nbVus <= nbCarac; ++nbVus)
		for (int flip(0); flip < 2; ++flip)
			for (int set(0); set < 3; ++set)
				if ( (set == 2 and (from[nbVus-1] ^ flip) == to[nbVus-1])
						or (set != 2 and (set ^ flip) == to[nbVus-1]))
				{
					int &cur = dp[nbVus][flip][set];

					for (int prvFlip(0); prvFlip < 2; ++prvFlip)
						for (int prvSet(0); prvSet < 3; ++prvSet)
						{
							int cost = (!prvFlip and flip) + (set != 2 and set != prvSet);
							cur = min(cur, cost + dp[nbVus-1][prvFlip][prvSet]);
						}
				}

	int ret = 1e9;
	for (int i(0); i < 2; ++i)
		for (int j(0); j < 3; ++j)
			ret = min(ret, dp[nbCarac][i][j]);
	cout << ret << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47180 KB Output is correct
2 Correct 23 ms 47244 KB Output is correct
3 Correct 23 ms 47272 KB Output is correct
4 Correct 23 ms 47196 KB Output is correct
5 Correct 23 ms 47284 KB Output is correct
6 Correct 22 ms 47216 KB Output is correct
7 Correct 22 ms 47276 KB Output is correct
8 Correct 24 ms 47176 KB Output is correct
9 Correct 23 ms 47244 KB Output is correct
10 Correct 22 ms 47280 KB Output is correct
11 Correct 23 ms 47184 KB Output is correct
12 Correct 23 ms 47264 KB Output is correct
13 Correct 21 ms 47172 KB Output is correct
14 Correct 23 ms 47144 KB Output is correct
15 Correct 23 ms 47184 KB Output is correct
16 Correct 24 ms 47172 KB Output is correct
17 Correct 23 ms 47168 KB Output is correct
18 Correct 23 ms 47236 KB Output is correct
19 Correct 22 ms 47180 KB Output is correct
20 Correct 24 ms 47232 KB Output is correct
21 Correct 21 ms 47172 KB Output is correct
22 Correct 23 ms 47184 KB Output is correct
23 Correct 23 ms 47240 KB Output is correct
24 Correct 23 ms 47232 KB Output is correct
25 Correct 24 ms 47172 KB Output is correct
26 Correct 23 ms 47216 KB Output is correct
27 Correct 23 ms 47208 KB Output is correct
28 Correct 25 ms 47288 KB Output is correct
29 Correct 23 ms 47284 KB Output is correct
30 Correct 23 ms 47172 KB Output is correct
31 Correct 23 ms 47220 KB Output is correct
32 Correct 23 ms 47180 KB Output is correct
33 Correct 23 ms 47284 KB Output is correct
34 Correct 23 ms 47196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47180 KB Output is correct
2 Correct 23 ms 47244 KB Output is correct
3 Correct 23 ms 47272 KB Output is correct
4 Correct 23 ms 47196 KB Output is correct
5 Correct 23 ms 47284 KB Output is correct
6 Correct 22 ms 47216 KB Output is correct
7 Correct 22 ms 47276 KB Output is correct
8 Correct 24 ms 47176 KB Output is correct
9 Correct 23 ms 47244 KB Output is correct
10 Correct 22 ms 47280 KB Output is correct
11 Correct 23 ms 47184 KB Output is correct
12 Correct 23 ms 47264 KB Output is correct
13 Correct 21 ms 47172 KB Output is correct
14 Correct 23 ms 47144 KB Output is correct
15 Correct 23 ms 47184 KB Output is correct
16 Correct 24 ms 47172 KB Output is correct
17 Correct 23 ms 47168 KB Output is correct
18 Correct 23 ms 47236 KB Output is correct
19 Correct 22 ms 47180 KB Output is correct
20 Correct 24 ms 47232 KB Output is correct
21 Correct 21 ms 47172 KB Output is correct
22 Correct 23 ms 47184 KB Output is correct
23 Correct 23 ms 47240 KB Output is correct
24 Correct 23 ms 47232 KB Output is correct
25 Correct 24 ms 47172 KB Output is correct
26 Correct 23 ms 47216 KB Output is correct
27 Correct 23 ms 47208 KB Output is correct
28 Correct 25 ms 47288 KB Output is correct
29 Correct 23 ms 47284 KB Output is correct
30 Correct 23 ms 47172 KB Output is correct
31 Correct 23 ms 47220 KB Output is correct
32 Correct 23 ms 47180 KB Output is correct
33 Correct 23 ms 47284 KB Output is correct
34 Correct 23 ms 47196 KB Output is correct
35 Correct 23 ms 47164 KB Output is correct
36 Correct 24 ms 47276 KB Output is correct
37 Correct 24 ms 47212 KB Output is correct
38 Correct 21 ms 47180 KB Output is correct
39 Correct 24 ms 47160 KB Output is correct
40 Correct 23 ms 47180 KB Output is correct
41 Correct 22 ms 47180 KB Output is correct
42 Correct 24 ms 47272 KB Output is correct
43 Correct 23 ms 47240 KB Output is correct
44 Correct 23 ms 47176 KB Output is correct
45 Correct 23 ms 47180 KB Output is correct
46 Correct 22 ms 47260 KB Output is correct
47 Correct 23 ms 47252 KB Output is correct
48 Correct 22 ms 47244 KB Output is correct
49 Correct 23 ms 47276 KB Output is correct
50 Correct 23 ms 47288 KB Output is correct
51 Correct 23 ms 47172 KB Output is correct
52 Correct 23 ms 47244 KB Output is correct
53 Correct 24 ms 47232 KB Output is correct
54 Correct 24 ms 47284 KB Output is correct
55 Correct 23 ms 47192 KB Output is correct
56 Correct 23 ms 47188 KB Output is correct
57 Correct 23 ms 47208 KB Output is correct
58 Correct 23 ms 47180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47216 KB Output is correct
2 Correct 23 ms 47236 KB Output is correct
3 Correct 24 ms 47264 KB Output is correct
4 Correct 26 ms 47260 KB Output is correct
5 Correct 26 ms 47220 KB Output is correct
6 Correct 23 ms 47180 KB Output is correct
7 Correct 62 ms 51448 KB Output is correct
8 Correct 63 ms 51348 KB Output is correct
9 Correct 62 ms 51384 KB Output is correct
10 Correct 63 ms 51348 KB Output is correct
11 Correct 64 ms 51356 KB Output is correct
12 Correct 62 ms 51352 KB Output is correct
13 Correct 63 ms 51444 KB Output is correct
14 Correct 77 ms 51356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47180 KB Output is correct
2 Correct 23 ms 47244 KB Output is correct
3 Correct 23 ms 47272 KB Output is correct
4 Correct 23 ms 47196 KB Output is correct
5 Correct 23 ms 47284 KB Output is correct
6 Correct 22 ms 47216 KB Output is correct
7 Correct 22 ms 47276 KB Output is correct
8 Correct 24 ms 47176 KB Output is correct
9 Correct 23 ms 47244 KB Output is correct
10 Correct 22 ms 47280 KB Output is correct
11 Correct 23 ms 47184 KB Output is correct
12 Correct 23 ms 47264 KB Output is correct
13 Correct 21 ms 47172 KB Output is correct
14 Correct 23 ms 47144 KB Output is correct
15 Correct 23 ms 47184 KB Output is correct
16 Correct 24 ms 47172 KB Output is correct
17 Correct 23 ms 47168 KB Output is correct
18 Correct 23 ms 47236 KB Output is correct
19 Correct 22 ms 47180 KB Output is correct
20 Correct 24 ms 47232 KB Output is correct
21 Correct 21 ms 47172 KB Output is correct
22 Correct 23 ms 47184 KB Output is correct
23 Correct 23 ms 47240 KB Output is correct
24 Correct 23 ms 47232 KB Output is correct
25 Correct 24 ms 47172 KB Output is correct
26 Correct 23 ms 47216 KB Output is correct
27 Correct 23 ms 47208 KB Output is correct
28 Correct 25 ms 47288 KB Output is correct
29 Correct 23 ms 47284 KB Output is correct
30 Correct 23 ms 47172 KB Output is correct
31 Correct 23 ms 47220 KB Output is correct
32 Correct 23 ms 47180 KB Output is correct
33 Correct 23 ms 47284 KB Output is correct
34 Correct 23 ms 47196 KB Output is correct
35 Correct 23 ms 47164 KB Output is correct
36 Correct 24 ms 47276 KB Output is correct
37 Correct 24 ms 47212 KB Output is correct
38 Correct 21 ms 47180 KB Output is correct
39 Correct 24 ms 47160 KB Output is correct
40 Correct 23 ms 47180 KB Output is correct
41 Correct 22 ms 47180 KB Output is correct
42 Correct 24 ms 47272 KB Output is correct
43 Correct 23 ms 47240 KB Output is correct
44 Correct 23 ms 47176 KB Output is correct
45 Correct 23 ms 47180 KB Output is correct
46 Correct 22 ms 47260 KB Output is correct
47 Correct 23 ms 47252 KB Output is correct
48 Correct 22 ms 47244 KB Output is correct
49 Correct 23 ms 47276 KB Output is correct
50 Correct 23 ms 47288 KB Output is correct
51 Correct 23 ms 47172 KB Output is correct
52 Correct 23 ms 47244 KB Output is correct
53 Correct 24 ms 47232 KB Output is correct
54 Correct 24 ms 47284 KB Output is correct
55 Correct 23 ms 47192 KB Output is correct
56 Correct 23 ms 47188 KB Output is correct
57 Correct 23 ms 47208 KB Output is correct
58 Correct 23 ms 47180 KB Output is correct
59 Correct 23 ms 47216 KB Output is correct
60 Correct 23 ms 47236 KB Output is correct
61 Correct 24 ms 47264 KB Output is correct
62 Correct 26 ms 47260 KB Output is correct
63 Correct 26 ms 47220 KB Output is correct
64 Correct 23 ms 47180 KB Output is correct
65 Correct 62 ms 51448 KB Output is correct
66 Correct 63 ms 51348 KB Output is correct
67 Correct 62 ms 51384 KB Output is correct
68 Correct 63 ms 51348 KB Output is correct
69 Correct 64 ms 51356 KB Output is correct
70 Correct 62 ms 51352 KB Output is correct
71 Correct 63 ms 51444 KB Output is correct
72 Correct 77 ms 51356 KB Output is correct
73 Correct 64 ms 51336 KB Output is correct
74 Correct 64 ms 51432 KB Output is correct
75 Correct 63 ms 51448 KB Output is correct
76 Correct 64 ms 51400 KB Output is correct
77 Correct 63 ms 51352 KB Output is correct
78 Correct 63 ms 51408 KB Output is correct
79 Correct 67 ms 51468 KB Output is correct
80 Correct 63 ms 51364 KB Output is correct
81 Correct 62 ms 51448 KB Output is correct
82 Correct 64 ms 51476 KB Output is correct
83 Correct 71 ms 51444 KB Output is correct
84 Correct 72 ms 51348 KB Output is correct
85 Correct 71 ms 51348 KB Output is correct
86 Correct 71 ms 51380 KB Output is correct
87 Correct 72 ms 51384 KB Output is correct
88 Correct 71 ms 51348 KB Output is correct
89 Correct 71 ms 51364 KB Output is correct
90 Correct 72 ms 51452 KB Output is correct
91 Correct 77 ms 51356 KB Output is correct
92 Correct 79 ms 51432 KB Output is correct
93 Correct 82 ms 51476 KB Output is correct
94 Correct 96 ms 51352 KB Output is correct
95 Correct 106 ms 51416 KB Output is correct
96 Correct 82 ms 51344 KB Output is correct
97 Correct 82 ms 51344 KB Output is correct
98 Correct 86 ms 51344 KB Output is correct
99 Correct 81 ms 51360 KB Output is correct
100 Correct 83 ms 51348 KB Output is correct
101 Correct 83 ms 51496 KB Output is correct
102 Correct 81 ms 51344 KB Output is correct