Submission #1081711

# Submission time Handle Problem Language Result Execution time Memory
1081711 2024-08-30T09:30:10 Z hahahaha Lamps (JOI19_lamps) C++17
100 / 100
63 ms 33872 KB
#include "bits/stdc++.h"
#define forr(_a,_b,_c) for(int _a = (_b); _a <= (_c); ++_a)
#define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> (_c);)
#define forf(_a,_b,_c) for(int _a = (_b); _a < (_c); ++_a)
#define st first
#define nd second
#define ll long long
#define ull unsigned long long
#define pii pair <int,int>
#define pll pair <ll,ll>
#define piii pair <int,pii>
#define vi vector <int>
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"
 
using namespace std;
const int N = 1e6 + 5;
const int mod = 1e9 + 7; // 998244353
const ll oo = 1e18;
 
int n;
int a[N], b[N];
int dp[N][3][2];
 
void to_nho_cau() {
    cin >> n;
    int dem1 = 0, dem0 = 0;
    forr(i, 1, n) {
        char x; cin >> x;
        a[i] = (x == '1') ? 1: 0;
    }
    forr(i, 1, n) {
        char x; cin >> x;
        b[i] = (x == '1') ? 1: 0;
    }
    memset(dp, 0x3f, sizeof dp);
    dp[0][0][0] = 0;
    forr(i, 1, n) {
        forr(j, 0, 2) {
            forr(k, 0, 1) {
                //j = 0 là giữ nguyên giá trị ban đầu
                //  = 1 là chuyển thành 0
                //  = 2 là chuyển thành 1
                //k = 0 nghĩa là đảo tại vị trí này
                int val = a[i];
                if(j == 1) val = 0;
                if(j == 2) val = 1;
                if(k == 1) val ^= 1;
                if(val != b[i]) continue;
                forr(j2, 0, 2) {
                    forr(k2, 0, 1) {
                        dp[i][j][k] = min(dp[i][j][k], dp[i-1][j2][k2] + (j > 0 && j != j2) + (k > 0 && k != k2));
                    }
                }
            }
        }
    }
    int ans = mod;
    forr(j, 0, 2) {
        forr(k, 0, 1) {
            ans = min(ans, dp[n][j][k]);
        }
    }
    cout << ans << "\n";
}
 
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    #ifdef LOCAL
        freopen(file".inp","r",stdin);
        freopen(file".out","w",stdout);
    #endif
    int t = 1;
    //cin >> t;
    while(t--) to_nho_cau();
}

Compilation message

lamp.cpp: In function 'void to_nho_cau()':
lamp.cpp:32:9: warning: unused variable 'dem1' [-Wunused-variable]
   32 |     int dem1 = 0, dem0 = 0;
      |         ^~~~
lamp.cpp:32:19: warning: unused variable 'dem0' [-Wunused-variable]
   32 |     int dem1 = 0, dem0 = 0;
      |                   ^~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 27224 KB Output is correct
2 Correct 3 ms 27228 KB Output is correct
3 Correct 4 ms 27204 KB Output is correct
4 Correct 4 ms 27228 KB Output is correct
5 Correct 4 ms 27224 KB Output is correct
6 Correct 3 ms 27088 KB Output is correct
7 Correct 3 ms 27308 KB Output is correct
8 Correct 3 ms 27228 KB Output is correct
9 Correct 3 ms 27228 KB Output is correct
10 Correct 3 ms 27228 KB Output is correct
11 Correct 3 ms 27480 KB Output is correct
12 Correct 4 ms 27228 KB Output is correct
13 Correct 4 ms 27228 KB Output is correct
14 Correct 4 ms 27228 KB Output is correct
15 Correct 4 ms 27228 KB Output is correct
16 Correct 4 ms 27228 KB Output is correct
17 Correct 4 ms 27228 KB Output is correct
18 Correct 3 ms 27224 KB Output is correct
19 Correct 3 ms 27228 KB Output is correct
20 Correct 4 ms 27228 KB Output is correct
21 Correct 4 ms 27224 KB Output is correct
22 Correct 3 ms 27228 KB Output is correct
23 Correct 4 ms 27236 KB Output is correct
24 Correct 4 ms 27228 KB Output is correct
25 Correct 4 ms 27228 KB Output is correct
26 Correct 3 ms 27228 KB Output is correct
27 Correct 3 ms 27228 KB Output is correct
28 Correct 3 ms 27228 KB Output is correct
29 Correct 4 ms 27228 KB Output is correct
30 Correct 3 ms 27228 KB Output is correct
31 Correct 3 ms 27228 KB Output is correct
32 Correct 3 ms 27228 KB Output is correct
33 Correct 3 ms 27228 KB Output is correct
34 Correct 3 ms 27228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 27224 KB Output is correct
2 Correct 3 ms 27228 KB Output is correct
3 Correct 4 ms 27204 KB Output is correct
4 Correct 4 ms 27228 KB Output is correct
5 Correct 4 ms 27224 KB Output is correct
6 Correct 3 ms 27088 KB Output is correct
7 Correct 3 ms 27308 KB Output is correct
8 Correct 3 ms 27228 KB Output is correct
9 Correct 3 ms 27228 KB Output is correct
10 Correct 3 ms 27228 KB Output is correct
11 Correct 3 ms 27480 KB Output is correct
12 Correct 4 ms 27228 KB Output is correct
13 Correct 4 ms 27228 KB Output is correct
14 Correct 4 ms 27228 KB Output is correct
15 Correct 4 ms 27228 KB Output is correct
16 Correct 4 ms 27228 KB Output is correct
17 Correct 4 ms 27228 KB Output is correct
18 Correct 3 ms 27224 KB Output is correct
19 Correct 3 ms 27228 KB Output is correct
20 Correct 4 ms 27228 KB Output is correct
21 Correct 4 ms 27224 KB Output is correct
22 Correct 3 ms 27228 KB Output is correct
23 Correct 4 ms 27236 KB Output is correct
24 Correct 4 ms 27228 KB Output is correct
25 Correct 4 ms 27228 KB Output is correct
26 Correct 3 ms 27228 KB Output is correct
27 Correct 3 ms 27228 KB Output is correct
28 Correct 3 ms 27228 KB Output is correct
29 Correct 4 ms 27228 KB Output is correct
30 Correct 3 ms 27228 KB Output is correct
31 Correct 3 ms 27228 KB Output is correct
32 Correct 3 ms 27228 KB Output is correct
33 Correct 3 ms 27228 KB Output is correct
34 Correct 3 ms 27228 KB Output is correct
35 Correct 4 ms 27224 KB Output is correct
36 Correct 3 ms 27228 KB Output is correct
37 Correct 3 ms 27228 KB Output is correct
38 Correct 4 ms 27224 KB Output is correct
39 Correct 3 ms 27228 KB Output is correct
40 Correct 3 ms 27228 KB Output is correct
41 Correct 3 ms 27100 KB Output is correct
42 Correct 3 ms 27228 KB Output is correct
43 Correct 3 ms 27228 KB Output is correct
44 Correct 3 ms 27224 KB Output is correct
45 Correct 4 ms 27088 KB Output is correct
46 Correct 3 ms 27292 KB Output is correct
47 Correct 4 ms 27480 KB Output is correct
48 Correct 5 ms 27228 KB Output is correct
49 Correct 3 ms 27228 KB Output is correct
50 Correct 4 ms 27092 KB Output is correct
51 Correct 4 ms 27228 KB Output is correct
52 Correct 5 ms 27228 KB Output is correct
53 Correct 5 ms 27480 KB Output is correct
54 Correct 4 ms 27228 KB Output is correct
55 Correct 3 ms 27228 KB Output is correct
56 Correct 4 ms 27228 KB Output is correct
57 Correct 4 ms 27228 KB Output is correct
58 Correct 3 ms 27228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 27224 KB Output is correct
2 Correct 3 ms 27228 KB Output is correct
3 Correct 3 ms 27228 KB Output is correct
4 Correct 3 ms 27228 KB Output is correct
5 Correct 3 ms 27224 KB Output is correct
6 Correct 3 ms 27228 KB Output is correct
7 Correct 56 ms 33472 KB Output is correct
8 Correct 39 ms 33616 KB Output is correct
9 Correct 40 ms 33616 KB Output is correct
10 Correct 44 ms 33616 KB Output is correct
11 Correct 44 ms 33628 KB Output is correct
12 Correct 40 ms 33628 KB Output is correct
13 Correct 41 ms 33872 KB Output is correct
14 Correct 40 ms 33616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 27224 KB Output is correct
2 Correct 3 ms 27228 KB Output is correct
3 Correct 4 ms 27204 KB Output is correct
4 Correct 4 ms 27228 KB Output is correct
5 Correct 4 ms 27224 KB Output is correct
6 Correct 3 ms 27088 KB Output is correct
7 Correct 3 ms 27308 KB Output is correct
8 Correct 3 ms 27228 KB Output is correct
9 Correct 3 ms 27228 KB Output is correct
10 Correct 3 ms 27228 KB Output is correct
11 Correct 3 ms 27480 KB Output is correct
12 Correct 4 ms 27228 KB Output is correct
13 Correct 4 ms 27228 KB Output is correct
14 Correct 4 ms 27228 KB Output is correct
15 Correct 4 ms 27228 KB Output is correct
16 Correct 4 ms 27228 KB Output is correct
17 Correct 4 ms 27228 KB Output is correct
18 Correct 3 ms 27224 KB Output is correct
19 Correct 3 ms 27228 KB Output is correct
20 Correct 4 ms 27228 KB Output is correct
21 Correct 4 ms 27224 KB Output is correct
22 Correct 3 ms 27228 KB Output is correct
23 Correct 4 ms 27236 KB Output is correct
24 Correct 4 ms 27228 KB Output is correct
25 Correct 4 ms 27228 KB Output is correct
26 Correct 3 ms 27228 KB Output is correct
27 Correct 3 ms 27228 KB Output is correct
28 Correct 3 ms 27228 KB Output is correct
29 Correct 4 ms 27228 KB Output is correct
30 Correct 3 ms 27228 KB Output is correct
31 Correct 3 ms 27228 KB Output is correct
32 Correct 3 ms 27228 KB Output is correct
33 Correct 3 ms 27228 KB Output is correct
34 Correct 3 ms 27228 KB Output is correct
35 Correct 4 ms 27224 KB Output is correct
36 Correct 3 ms 27228 KB Output is correct
37 Correct 3 ms 27228 KB Output is correct
38 Correct 4 ms 27224 KB Output is correct
39 Correct 3 ms 27228 KB Output is correct
40 Correct 3 ms 27228 KB Output is correct
41 Correct 3 ms 27100 KB Output is correct
42 Correct 3 ms 27228 KB Output is correct
43 Correct 3 ms 27228 KB Output is correct
44 Correct 3 ms 27224 KB Output is correct
45 Correct 4 ms 27088 KB Output is correct
46 Correct 3 ms 27292 KB Output is correct
47 Correct 4 ms 27480 KB Output is correct
48 Correct 5 ms 27228 KB Output is correct
49 Correct 3 ms 27228 KB Output is correct
50 Correct 4 ms 27092 KB Output is correct
51 Correct 4 ms 27228 KB Output is correct
52 Correct 5 ms 27228 KB Output is correct
53 Correct 5 ms 27480 KB Output is correct
54 Correct 4 ms 27228 KB Output is correct
55 Correct 3 ms 27228 KB Output is correct
56 Correct 4 ms 27228 KB Output is correct
57 Correct 4 ms 27228 KB Output is correct
58 Correct 3 ms 27228 KB Output is correct
59 Correct 4 ms 27224 KB Output is correct
60 Correct 3 ms 27228 KB Output is correct
61 Correct 3 ms 27228 KB Output is correct
62 Correct 3 ms 27228 KB Output is correct
63 Correct 3 ms 27224 KB Output is correct
64 Correct 3 ms 27228 KB Output is correct
65 Correct 56 ms 33472 KB Output is correct
66 Correct 39 ms 33616 KB Output is correct
67 Correct 40 ms 33616 KB Output is correct
68 Correct 44 ms 33616 KB Output is correct
69 Correct 44 ms 33628 KB Output is correct
70 Correct 40 ms 33628 KB Output is correct
71 Correct 41 ms 33872 KB Output is correct
72 Correct 40 ms 33616 KB Output is correct
73 Correct 38 ms 33616 KB Output is correct
74 Correct 41 ms 33708 KB Output is correct
75 Correct 40 ms 33496 KB Output is correct
76 Correct 57 ms 33616 KB Output is correct
77 Correct 46 ms 33708 KB Output is correct
78 Correct 39 ms 33624 KB Output is correct
79 Correct 37 ms 33620 KB Output is correct
80 Correct 38 ms 33628 KB Output is correct
81 Correct 42 ms 33624 KB Output is correct
82 Correct 45 ms 33628 KB Output is correct
83 Correct 45 ms 33620 KB Output is correct
84 Correct 45 ms 33704 KB Output is correct
85 Correct 43 ms 33628 KB Output is correct
86 Correct 47 ms 33580 KB Output is correct
87 Correct 47 ms 33628 KB Output is correct
88 Correct 46 ms 33624 KB Output is correct
89 Correct 52 ms 33620 KB Output is correct
90 Correct 46 ms 33616 KB Output is correct
91 Correct 48 ms 33708 KB Output is correct
92 Correct 63 ms 33712 KB Output is correct
93 Correct 48 ms 33508 KB Output is correct
94 Correct 47 ms 33628 KB Output is correct
95 Correct 59 ms 33624 KB Output is correct
96 Correct 48 ms 33624 KB Output is correct
97 Correct 48 ms 33708 KB Output is correct
98 Correct 47 ms 33624 KB Output is correct
99 Correct 49 ms 33704 KB Output is correct
100 Correct 56 ms 33616 KB Output is correct
101 Correct 47 ms 33616 KB Output is correct
102 Correct 46 ms 33624 KB Output is correct