답안 #105172

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
105172 2019-04-10T21:34:01 Z reality Lamps (JOI19_lamps) C++17
100 / 100
397 ms 35704 KB
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define vii vector < pii >
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;}
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = 1e6 + 5;
const int oo = 1e9;
char A[N];
char B[N];
int dp[N][2][2][2];
int main(void) {
    int n;
    cin>>n;
    cin>>(A+1)>>(B+1);
    for (int i = 0;i <= n;++i)
    	for (int a = 0;a < 2;++a)
    		for (int b = 0;b < 2;++b)
    			for (int c = 0;c < 2;++c)
    				dp[i][a][b][c] = oo;
    dp[0][0][0][0] = 0;
    for (int i = 1;i <= n;++i) {
    	for (int a = 0;a < 2;++a)
    		for (int b = 0;b < 2;++b)
    			if (!a || !b)
    				for (int c = 0;c < 2;++c)
    					for (int d = 0;d < 2;++d)
    						if (!c || !d)
    							for (int e = 0;e < 2;++e) 
	    							for (int f = 0;f < 2;++f) {
	    								if (c) {
	    									if ((B[i] == '0') ^ e ^ 1) {
	    										continue;
	    									}
	    								} else
	    								if (d) {
	    									if ((B[i] == '1') ^ e ^ 1) {
	    										continue;
	    									}
	    								} else
	    								if (!c && !d) {
	    									if ((A[i] == B[i]) ^ e ^ 1) {
	    										continue;
	    									}
	    								}
	    								smin(dp[i][c][d][e],dp[i - 1][a][b][f] + (c && c != a) + (d && d != b) + (e && e != f));
	    							}
    }
    int ans = oo;
    for (int a = 0;a < 2;++a)
    	for (int b = 0;b < 2;++b)
    		for (int c = 0;c < 2;++c)
    			smin(ans,dp[n][a][b][c]);
    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 3 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 3 ms 384 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 3 ms 384 KB Output is correct
49 Correct 2 ms 384 KB Output is correct
50 Correct 3 ms 384 KB Output is correct
51 Correct 3 ms 384 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 3 ms 256 KB Output is correct
54 Correct 3 ms 384 KB Output is correct
55 Correct 3 ms 384 KB Output is correct
56 Correct 2 ms 384 KB Output is correct
57 Correct 2 ms 384 KB Output is correct
58 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 295 ms 33716 KB Output is correct
8 Correct 317 ms 33656 KB Output is correct
9 Correct 284 ms 33656 KB Output is correct
10 Correct 299 ms 33624 KB Output is correct
11 Correct 303 ms 33716 KB Output is correct
12 Correct 274 ms 33656 KB Output is correct
13 Correct 284 ms 33656 KB Output is correct
14 Correct 268 ms 33656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 3 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 3 ms 384 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 3 ms 384 KB Output is correct
49 Correct 2 ms 384 KB Output is correct
50 Correct 3 ms 384 KB Output is correct
51 Correct 3 ms 384 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 3 ms 256 KB Output is correct
54 Correct 3 ms 384 KB Output is correct
55 Correct 3 ms 384 KB Output is correct
56 Correct 2 ms 384 KB Output is correct
57 Correct 2 ms 384 KB Output is correct
58 Correct 2 ms 384 KB Output is correct
59 Correct 2 ms 384 KB Output is correct
60 Correct 2 ms 384 KB Output is correct
61 Correct 2 ms 384 KB Output is correct
62 Correct 3 ms 384 KB Output is correct
63 Correct 2 ms 384 KB Output is correct
64 Correct 2 ms 384 KB Output is correct
65 Correct 295 ms 33716 KB Output is correct
66 Correct 317 ms 33656 KB Output is correct
67 Correct 284 ms 33656 KB Output is correct
68 Correct 299 ms 33624 KB Output is correct
69 Correct 303 ms 33716 KB Output is correct
70 Correct 274 ms 33656 KB Output is correct
71 Correct 284 ms 33656 KB Output is correct
72 Correct 268 ms 33656 KB Output is correct
73 Correct 281 ms 35576 KB Output is correct
74 Correct 288 ms 35548 KB Output is correct
75 Correct 307 ms 35580 KB Output is correct
76 Correct 285 ms 35580 KB Output is correct
77 Correct 313 ms 35576 KB Output is correct
78 Correct 299 ms 35576 KB Output is correct
79 Correct 331 ms 35556 KB Output is correct
80 Correct 300 ms 35576 KB Output is correct
81 Correct 302 ms 35580 KB Output is correct
82 Correct 312 ms 35704 KB Output is correct
83 Correct 305 ms 35576 KB Output is correct
84 Correct 325 ms 35704 KB Output is correct
85 Correct 311 ms 35444 KB Output is correct
86 Correct 286 ms 35576 KB Output is correct
87 Correct 292 ms 35676 KB Output is correct
88 Correct 296 ms 35604 KB Output is correct
89 Correct 276 ms 35560 KB Output is correct
90 Correct 285 ms 35576 KB Output is correct
91 Correct 292 ms 35576 KB Output is correct
92 Correct 291 ms 35576 KB Output is correct
93 Correct 314 ms 35616 KB Output is correct
94 Correct 397 ms 35640 KB Output is correct
95 Correct 346 ms 35540 KB Output is correct
96 Correct 278 ms 35628 KB Output is correct
97 Correct 309 ms 35576 KB Output is correct
98 Correct 306 ms 35584 KB Output is correct
99 Correct 344 ms 35452 KB Output is correct
100 Correct 281 ms 35576 KB Output is correct
101 Correct 285 ms 35584 KB Output is correct
102 Correct 383 ms 35448 KB Output is correct