답안 #964224

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964224 2024-04-16T12:51:09 Z Cookie Lamps (JOI19_lamps) C++14
100 / 100
83 ms 33832 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod = 1e9 + 7, pr = 31;
const int mxn = 1e6 + 5, mxq = 1e5 + 5, sq = 500, mxv = 5e4 + 1;
//const int base = (1 <<18);
const ll inf = 1e9 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
int n;
int dp[mxn + 1][3][2];
int a[mxn + 1], b[mxn + 1];
void ckmin(int &a, int b){
    if(a > b)a = b;
}
void solve(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        char c; cin >> c; a[i] = (c - '0');
    }
    for(int i = 1; i <= n; i++){
        char c; cin >> c; b[i] = (c - '0');
    }
    for(int i = 0; i <= n; i++){
        for(int j = 0; j < 3; j++){
            dp[i][j][0] = dp[i][j][1] = inf;
        }
    }
    dp[0][0][0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 2; k++){
                for(int l = 0; l < 3; l++){
                    for(int z = 0; z < 2; z++){
                        int bit;
                        if(l == 0)bit = a[i + 1];
                        else bit = l - 1;
                        if(z)bit = !bit;
                        if(bit == b[i + 1]){
                            ckmin(dp[i + 1][l][z], dp[i][j][k] + (j != l && l) + (k < z));
                        }
                    }
                }
            }
        }
    }
    int ans = inf;
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 2; j++){
            ckmin(ans, dp[n][i][j]);
        }
    }
    cout << ans;
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("DATA.inp", "r", stdin);
    //freopen("DATA.out", "w", stdout);
    int tt; tt = 1;
    while(tt--){
        solve();
 
    }
    return(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4564 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4568 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4564 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4568 KB Output is correct
21 Correct 2 ms 4556 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4564 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4568 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4564 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4568 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4564 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4568 KB Output is correct
21 Correct 2 ms 4556 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4564 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4568 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4440 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4560 KB Output is correct
46 Correct 1 ms 4696 KB Output is correct
47 Correct 1 ms 4584 KB Output is correct
48 Correct 1 ms 4440 KB Output is correct
49 Correct 1 ms 4440 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4560 KB Output is correct
53 Correct 1 ms 4440 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 1 ms 4440 KB Output is correct
56 Correct 1 ms 4444 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4564 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 77 ms 33664 KB Output is correct
8 Correct 65 ms 33704 KB Output is correct
9 Correct 76 ms 33620 KB Output is correct
10 Correct 75 ms 33832 KB Output is correct
11 Correct 66 ms 33708 KB Output is correct
12 Correct 58 ms 33624 KB Output is correct
13 Correct 60 ms 33628 KB Output is correct
14 Correct 60 ms 33616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4564 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4568 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4564 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4568 KB Output is correct
21 Correct 2 ms 4556 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4564 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4568 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4440 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4560 KB Output is correct
46 Correct 1 ms 4696 KB Output is correct
47 Correct 1 ms 4584 KB Output is correct
48 Correct 1 ms 4440 KB Output is correct
49 Correct 1 ms 4440 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4560 KB Output is correct
53 Correct 1 ms 4440 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 1 ms 4440 KB Output is correct
56 Correct 1 ms 4444 KB Output is correct
57 Correct 1 ms 4444 KB Output is correct
58 Correct 1 ms 4444 KB Output is correct
59 Correct 1 ms 4444 KB Output is correct
60 Correct 1 ms 4444 KB Output is correct
61 Correct 1 ms 4564 KB Output is correct
62 Correct 1 ms 4444 KB Output is correct
63 Correct 1 ms 4444 KB Output is correct
64 Correct 1 ms 4444 KB Output is correct
65 Correct 77 ms 33664 KB Output is correct
66 Correct 65 ms 33704 KB Output is correct
67 Correct 76 ms 33620 KB Output is correct
68 Correct 75 ms 33832 KB Output is correct
69 Correct 66 ms 33708 KB Output is correct
70 Correct 58 ms 33624 KB Output is correct
71 Correct 60 ms 33628 KB Output is correct
72 Correct 60 ms 33616 KB Output is correct
73 Correct 78 ms 33708 KB Output is correct
74 Correct 65 ms 33604 KB Output is correct
75 Correct 61 ms 33712 KB Output is correct
76 Correct 60 ms 33676 KB Output is correct
77 Correct 75 ms 33624 KB Output is correct
78 Correct 66 ms 33708 KB Output is correct
79 Correct 67 ms 33628 KB Output is correct
80 Correct 60 ms 33616 KB Output is correct
81 Correct 65 ms 33492 KB Output is correct
82 Correct 65 ms 33708 KB Output is correct
83 Correct 76 ms 33616 KB Output is correct
84 Correct 71 ms 33708 KB Output is correct
85 Correct 74 ms 33704 KB Output is correct
86 Correct 75 ms 33616 KB Output is correct
87 Correct 72 ms 33616 KB Output is correct
88 Correct 70 ms 33708 KB Output is correct
89 Correct 77 ms 33704 KB Output is correct
90 Correct 79 ms 33576 KB Output is correct
91 Correct 75 ms 33704 KB Output is correct
92 Correct 83 ms 33708 KB Output is correct
93 Correct 82 ms 33704 KB Output is correct
94 Correct 78 ms 33536 KB Output is correct
95 Correct 79 ms 33628 KB Output is correct
96 Correct 82 ms 33704 KB Output is correct
97 Correct 81 ms 33616 KB Output is correct
98 Correct 80 ms 33704 KB Output is correct
99 Correct 77 ms 33612 KB Output is correct
100 Correct 78 ms 33620 KB Output is correct
101 Correct 79 ms 33712 KB Output is correct
102 Correct 81 ms 33708 KB Output is correct