Submission #623834

# Submission time Handle Problem Language Result Execution time Memory
623834 2022-08-06T15:32:50 Z Arnch Lamps (JOI19_lamps) C++17
100 / 100
78 ms 35224 KB
// oooo
/*
 har chi delet mikhad bebar ~
 gitar o ba khodet nabar! ~
 ;Amoo_Hasan;
*/

#include<bits/stdc++.h>
//#pragma GCC optimize("O3,no-stack-protector,unroll-loops")
//#pragma GCC target("avx2,fma")

using namespace std;

typedef long long ll;
typedef long double ld;

#define Sz(x) int((x).size())
#define All(x) (x).begin(), (x).end()
#define wtf(x) cout<<#x <<" : " <<x <<endl

constexpr ll inf = 1e18, N = 1e6 + 10, mod = 1e9 + 7, pr = 1000696969;

ll dp[N][3];
int A[N], B[N];

int main() {
    ios :: sync_with_stdio(0), cin.tie(0);

	int n; cin >>n;
	string a, b; cin >>a >>b;

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

	memset(dp, 63, sizeof(dp));
	dp[0][0] = 0;

	for(int i = 1; i <= n; i++) {
		for(int j = 0; j < 3; j++) {
			for(int k = 0; k < 3; k++) {
				if(j != 0 && j == k) {
					if(k == B[i - 1] && j != B[i]) {
						dp[i][j] = min(dp[i][j], dp[i - 1][k] + 2);
						continue;
					}
					dp[i][j] = min(dp[i][j], dp[i - 1][k]);
					continue;
				}
				if(j == 0) {
					if(k == 0) {
						if(A[i] != B[i] && A[i - 1] == B[i - 1]) {
							dp[i][j] = min(dp[i][j], dp[i - 1][k] + 2);
							continue;
						}
						dp[i][j] = min(dp[i][j], dp[i - 1][k]);
						continue;
					}
					if(A[i] != B[i] && B[i - 1] == k) {
						dp[i][j] = min(dp[i][j], dp[i - 1][k] + 2);
						continue;
					}
					dp[i][j] = min(dp[i][j], dp[i - 1][k]);
					continue;
				}
				if(k == 0) {
					if(A[i - 1] == B[i - 1] && j != B[i]) {
						dp[i][j] = min(dp[i][j], dp[i - 1][k] + 4);
						continue;
					}
					dp[i][j] = min(dp[i][j], dp[i - 1][k] + 2);
					continue;
				}
				if(k == B[i - 1] && j != B[i]) {
					dp[i][j] = min(dp[i][j], dp[i - 1][k] + 4);
					continue;
				}
				dp[i][j] = min(dp[i][j], dp[i - 1][k] + 2);
				continue;
			}
		}
	}

	/*for(int i = 1; i <= n; i++) {
		for(int j = 0; j < 3; j++) {
			cout<<"^^" <<i <<" " <<j <<" " <<dp[i][j] / 2 <<endl;
		}
	}*/

	ll ans = inf;
	for(int i = 0; i < 3; i++) ans = min(ans, dp[n][i]);

	cout<<ans / 2;

    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 12 ms 23728 KB Output is correct
3 Correct 10 ms 23732 KB Output is correct
4 Correct 11 ms 23764 KB Output is correct
5 Correct 12 ms 23728 KB Output is correct
6 Correct 11 ms 23792 KB Output is correct
7 Correct 10 ms 23764 KB Output is correct
8 Correct 10 ms 23764 KB Output is correct
9 Correct 10 ms 23724 KB Output is correct
10 Correct 10 ms 23796 KB Output is correct
11 Correct 9 ms 23764 KB Output is correct
12 Correct 11 ms 23824 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 10 ms 23764 KB Output is correct
15 Correct 10 ms 23764 KB Output is correct
16 Correct 12 ms 23788 KB Output is correct
17 Correct 10 ms 23764 KB Output is correct
18 Correct 10 ms 23764 KB Output is correct
19 Correct 10 ms 23804 KB Output is correct
20 Correct 10 ms 23764 KB Output is correct
21 Correct 11 ms 23764 KB Output is correct
22 Correct 12 ms 23824 KB Output is correct
23 Correct 11 ms 23756 KB Output is correct
24 Correct 11 ms 23764 KB Output is correct
25 Correct 10 ms 23764 KB Output is correct
26 Correct 11 ms 23752 KB Output is correct
27 Correct 10 ms 23712 KB Output is correct
28 Correct 10 ms 23764 KB Output is correct
29 Correct 10 ms 23764 KB Output is correct
30 Correct 9 ms 23716 KB Output is correct
31 Correct 10 ms 23764 KB Output is correct
32 Correct 11 ms 23784 KB Output is correct
33 Correct 10 ms 23764 KB Output is correct
34 Correct 10 ms 23752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 12 ms 23728 KB Output is correct
3 Correct 10 ms 23732 KB Output is correct
4 Correct 11 ms 23764 KB Output is correct
5 Correct 12 ms 23728 KB Output is correct
6 Correct 11 ms 23792 KB Output is correct
7 Correct 10 ms 23764 KB Output is correct
8 Correct 10 ms 23764 KB Output is correct
9 Correct 10 ms 23724 KB Output is correct
10 Correct 10 ms 23796 KB Output is correct
11 Correct 9 ms 23764 KB Output is correct
12 Correct 11 ms 23824 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 10 ms 23764 KB Output is correct
15 Correct 10 ms 23764 KB Output is correct
16 Correct 12 ms 23788 KB Output is correct
17 Correct 10 ms 23764 KB Output is correct
18 Correct 10 ms 23764 KB Output is correct
19 Correct 10 ms 23804 KB Output is correct
20 Correct 10 ms 23764 KB Output is correct
21 Correct 11 ms 23764 KB Output is correct
22 Correct 12 ms 23824 KB Output is correct
23 Correct 11 ms 23756 KB Output is correct
24 Correct 11 ms 23764 KB Output is correct
25 Correct 10 ms 23764 KB Output is correct
26 Correct 11 ms 23752 KB Output is correct
27 Correct 10 ms 23712 KB Output is correct
28 Correct 10 ms 23764 KB Output is correct
29 Correct 10 ms 23764 KB Output is correct
30 Correct 9 ms 23716 KB Output is correct
31 Correct 10 ms 23764 KB Output is correct
32 Correct 11 ms 23784 KB Output is correct
33 Correct 10 ms 23764 KB Output is correct
34 Correct 10 ms 23752 KB Output is correct
35 Correct 12 ms 23764 KB Output is correct
36 Correct 10 ms 23764 KB Output is correct
37 Correct 10 ms 23756 KB Output is correct
38 Correct 10 ms 23796 KB Output is correct
39 Correct 10 ms 23756 KB Output is correct
40 Correct 10 ms 23764 KB Output is correct
41 Correct 11 ms 23756 KB Output is correct
42 Correct 10 ms 23832 KB Output is correct
43 Correct 11 ms 23764 KB Output is correct
44 Correct 10 ms 23764 KB Output is correct
45 Correct 10 ms 23764 KB Output is correct
46 Correct 10 ms 23764 KB Output is correct
47 Correct 10 ms 23828 KB Output is correct
48 Correct 11 ms 23764 KB Output is correct
49 Correct 11 ms 23736 KB Output is correct
50 Correct 10 ms 23764 KB Output is correct
51 Correct 10 ms 23824 KB Output is correct
52 Correct 10 ms 23764 KB Output is correct
53 Correct 10 ms 23752 KB Output is correct
54 Correct 10 ms 23764 KB Output is correct
55 Correct 10 ms 23724 KB Output is correct
56 Correct 10 ms 23832 KB Output is correct
57 Correct 10 ms 23772 KB Output is correct
58 Correct 10 ms 23804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 10 ms 23764 KB Output is correct
3 Correct 11 ms 23780 KB Output is correct
4 Correct 11 ms 23764 KB Output is correct
5 Correct 10 ms 23764 KB Output is correct
6 Correct 10 ms 23764 KB Output is correct
7 Correct 39 ms 33724 KB Output is correct
8 Correct 42 ms 33676 KB Output is correct
9 Correct 44 ms 33672 KB Output is correct
10 Correct 42 ms 33700 KB Output is correct
11 Correct 46 ms 33700 KB Output is correct
12 Correct 42 ms 33632 KB Output is correct
13 Correct 41 ms 33700 KB Output is correct
14 Correct 43 ms 33688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 12 ms 23728 KB Output is correct
3 Correct 10 ms 23732 KB Output is correct
4 Correct 11 ms 23764 KB Output is correct
5 Correct 12 ms 23728 KB Output is correct
6 Correct 11 ms 23792 KB Output is correct
7 Correct 10 ms 23764 KB Output is correct
8 Correct 10 ms 23764 KB Output is correct
9 Correct 10 ms 23724 KB Output is correct
10 Correct 10 ms 23796 KB Output is correct
11 Correct 9 ms 23764 KB Output is correct
12 Correct 11 ms 23824 KB Output is correct
13 Correct 11 ms 23764 KB Output is correct
14 Correct 10 ms 23764 KB Output is correct
15 Correct 10 ms 23764 KB Output is correct
16 Correct 12 ms 23788 KB Output is correct
17 Correct 10 ms 23764 KB Output is correct
18 Correct 10 ms 23764 KB Output is correct
19 Correct 10 ms 23804 KB Output is correct
20 Correct 10 ms 23764 KB Output is correct
21 Correct 11 ms 23764 KB Output is correct
22 Correct 12 ms 23824 KB Output is correct
23 Correct 11 ms 23756 KB Output is correct
24 Correct 11 ms 23764 KB Output is correct
25 Correct 10 ms 23764 KB Output is correct
26 Correct 11 ms 23752 KB Output is correct
27 Correct 10 ms 23712 KB Output is correct
28 Correct 10 ms 23764 KB Output is correct
29 Correct 10 ms 23764 KB Output is correct
30 Correct 9 ms 23716 KB Output is correct
31 Correct 10 ms 23764 KB Output is correct
32 Correct 11 ms 23784 KB Output is correct
33 Correct 10 ms 23764 KB Output is correct
34 Correct 10 ms 23752 KB Output is correct
35 Correct 12 ms 23764 KB Output is correct
36 Correct 10 ms 23764 KB Output is correct
37 Correct 10 ms 23756 KB Output is correct
38 Correct 10 ms 23796 KB Output is correct
39 Correct 10 ms 23756 KB Output is correct
40 Correct 10 ms 23764 KB Output is correct
41 Correct 11 ms 23756 KB Output is correct
42 Correct 10 ms 23832 KB Output is correct
43 Correct 11 ms 23764 KB Output is correct
44 Correct 10 ms 23764 KB Output is correct
45 Correct 10 ms 23764 KB Output is correct
46 Correct 10 ms 23764 KB Output is correct
47 Correct 10 ms 23828 KB Output is correct
48 Correct 11 ms 23764 KB Output is correct
49 Correct 11 ms 23736 KB Output is correct
50 Correct 10 ms 23764 KB Output is correct
51 Correct 10 ms 23824 KB Output is correct
52 Correct 10 ms 23764 KB Output is correct
53 Correct 10 ms 23752 KB Output is correct
54 Correct 10 ms 23764 KB Output is correct
55 Correct 10 ms 23724 KB Output is correct
56 Correct 10 ms 23832 KB Output is correct
57 Correct 10 ms 23772 KB Output is correct
58 Correct 10 ms 23804 KB Output is correct
59 Correct 10 ms 23764 KB Output is correct
60 Correct 10 ms 23764 KB Output is correct
61 Correct 11 ms 23780 KB Output is correct
62 Correct 11 ms 23764 KB Output is correct
63 Correct 10 ms 23764 KB Output is correct
64 Correct 10 ms 23764 KB Output is correct
65 Correct 39 ms 33724 KB Output is correct
66 Correct 42 ms 33676 KB Output is correct
67 Correct 44 ms 33672 KB Output is correct
68 Correct 42 ms 33700 KB Output is correct
69 Correct 46 ms 33700 KB Output is correct
70 Correct 42 ms 33632 KB Output is correct
71 Correct 41 ms 33700 KB Output is correct
72 Correct 43 ms 33688 KB Output is correct
73 Correct 45 ms 35104 KB Output is correct
74 Correct 46 ms 35104 KB Output is correct
75 Correct 42 ms 35124 KB Output is correct
76 Correct 41 ms 35128 KB Output is correct
77 Correct 42 ms 35124 KB Output is correct
78 Correct 45 ms 35224 KB Output is correct
79 Correct 44 ms 35224 KB Output is correct
80 Correct 44 ms 35064 KB Output is correct
81 Correct 46 ms 35120 KB Output is correct
82 Correct 46 ms 35044 KB Output is correct
83 Correct 49 ms 35184 KB Output is correct
84 Correct 50 ms 35012 KB Output is correct
85 Correct 48 ms 35064 KB Output is correct
86 Correct 48 ms 35132 KB Output is correct
87 Correct 52 ms 35076 KB Output is correct
88 Correct 54 ms 35104 KB Output is correct
89 Correct 48 ms 35140 KB Output is correct
90 Correct 48 ms 35128 KB Output is correct
91 Correct 50 ms 35124 KB Output is correct
92 Correct 55 ms 35104 KB Output is correct
93 Correct 54 ms 35148 KB Output is correct
94 Correct 52 ms 35160 KB Output is correct
95 Correct 51 ms 35096 KB Output is correct
96 Correct 52 ms 35128 KB Output is correct
97 Correct 56 ms 35192 KB Output is correct
98 Correct 78 ms 35036 KB Output is correct
99 Correct 55 ms 35108 KB Output is correct
100 Correct 53 ms 35096 KB Output is correct
101 Correct 55 ms 35132 KB Output is correct
102 Correct 52 ms 35132 KB Output is correct