답안 #702637

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
702637 2023-02-24T16:32:39 Z urosk Lamps (JOI19_lamps) C++14
100 / 100
45 ms 42508 KB
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include "bits/stdc++.h"
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}

#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);

using namespace std;
#define maxn 1000005
ll n;
ll a[maxn],b[maxn];
ll dp[maxn][3];
void tc(){
    cin >> n;
    string s;
    cin >> s;
    for(ll i = 1;i<=n;i++) a[i] = s[i-1]-'0';
    cin >> s;
    for(ll i = 1;i<=n;i++) b[i] = s[i-1]-'0';
    dp[0][1] = dp[0][2] = llinf;
    for(ll i = 1;i<=n;i++){
        for(ll k = 0;k<3;k++){
            dp[i][k] = llinf;
            for(ll j = 0;j<3;j++){
                ll x;
                if(k==0) x = a[i]^(dp[i-1][j]&1);
                else x = (k-1)^(dp[i-1][j]&1);
                dp[i][k] = min(dp[i][k],dp[i-1][j]+(k!=0&&k!=j)*2+(b[i]!=x));
            }
        }
    }
    ll ans = llinf;
    for(ll i = 0;i<3;i++){
        ans = min(ans,dp[n][i]+(dp[n][i]&1));
    }
    ans/=2;
    cout<<ans<<endl;
}
int main(){
	daj_mi_malo_vremena
    int t; t = 1;
    while(t--){
        tc();
    }
	return 0;
}
/**
8
11011100
01101001

13
1010010010100
0000111001011

18
001100010010000110
110110001000100101
**/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 324 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 324 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 328 KB Output is correct
41 Correct 1 ms 328 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 328 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 324 KB Output is correct
53 Correct 1 ms 328 KB Output is correct
54 Correct 1 ms 328 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 328 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 40 ms 42384 KB Output is correct
8 Correct 40 ms 42484 KB Output is correct
9 Correct 40 ms 42456 KB Output is correct
10 Correct 40 ms 42388 KB Output is correct
11 Correct 39 ms 42400 KB Output is correct
12 Correct 41 ms 42392 KB Output is correct
13 Correct 40 ms 42384 KB Output is correct
14 Correct 40 ms 42396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 324 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 328 KB Output is correct
41 Correct 1 ms 328 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 328 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 324 KB Output is correct
53 Correct 1 ms 328 KB Output is correct
54 Correct 1 ms 328 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 328 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 40 ms 42384 KB Output is correct
66 Correct 40 ms 42484 KB Output is correct
67 Correct 40 ms 42456 KB Output is correct
68 Correct 40 ms 42388 KB Output is correct
69 Correct 39 ms 42400 KB Output is correct
70 Correct 41 ms 42392 KB Output is correct
71 Correct 40 ms 42384 KB Output is correct
72 Correct 40 ms 42396 KB Output is correct
73 Correct 40 ms 42504 KB Output is correct
74 Correct 42 ms 42488 KB Output is correct
75 Correct 42 ms 42404 KB Output is correct
76 Correct 41 ms 42396 KB Output is correct
77 Correct 41 ms 42448 KB Output is correct
78 Correct 45 ms 42436 KB Output is correct
79 Correct 41 ms 42404 KB Output is correct
80 Correct 41 ms 42404 KB Output is correct
81 Correct 41 ms 42452 KB Output is correct
82 Correct 45 ms 42508 KB Output is correct
83 Correct 41 ms 42396 KB Output is correct
84 Correct 42 ms 42400 KB Output is correct
85 Correct 41 ms 42456 KB Output is correct
86 Correct 40 ms 42504 KB Output is correct
87 Correct 41 ms 42472 KB Output is correct
88 Correct 42 ms 42492 KB Output is correct
89 Correct 41 ms 42468 KB Output is correct
90 Correct 40 ms 42464 KB Output is correct
91 Correct 42 ms 42436 KB Output is correct
92 Correct 41 ms 42396 KB Output is correct
93 Correct 41 ms 42396 KB Output is correct
94 Correct 41 ms 42384 KB Output is correct
95 Correct 40 ms 42388 KB Output is correct
96 Correct 41 ms 42448 KB Output is correct
97 Correct 42 ms 42504 KB Output is correct
98 Correct 40 ms 42448 KB Output is correct
99 Correct 40 ms 42432 KB Output is correct
100 Correct 40 ms 42464 KB Output is correct
101 Correct 41 ms 42416 KB Output is correct
102 Correct 42 ms 42384 KB Output is correct