Submission #488460

# Submission time Handle Problem Language Result Execution time Memory
488460 2021-11-19T05:51:57 Z Theo830 Lamps (JOI19_lamps) C++17
100 / 100
180 ms 145376 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
ll dp[1000005][3][2];
string a,b;
ll n;
ll solve(ll idx,ll j1,ll j2){
    if(dp[idx][j1][j2] != -1){
        return dp[idx][j1][j2];
    }
    if(idx == n){
        return 0;
    }
    ll ans = INF;
    f(k1,0,3){
        f(k2,0,2){
            char v = a[idx];
            if(k1){
                v = k1 - 1 + '0';
            }
            if(k2){
                v = ((v - '0') ^ 1) + '0';
            }
            if(b[idx] == v){
                ans = min(ans,solve(idx+1,k1,k2) + (k1 != j1 && k1 != 0) + (k2 != j2 && k2 != 0));
            }
        }
    }
    return dp[idx][j1][j2] = ans;
}
int main(void){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    cin>>a>>b;
    memset(dp,-1,sizeof dp);
    cout<<solve(0,0,0)<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47184 KB Output is correct
2 Correct 20 ms 47236 KB Output is correct
3 Correct 20 ms 47172 KB Output is correct
4 Correct 19 ms 47276 KB Output is correct
5 Correct 20 ms 47200 KB Output is correct
6 Correct 26 ms 47204 KB Output is correct
7 Correct 26 ms 47264 KB Output is correct
8 Correct 20 ms 47168 KB Output is correct
9 Correct 21 ms 47184 KB Output is correct
10 Correct 27 ms 47176 KB Output is correct
11 Correct 20 ms 47204 KB Output is correct
12 Correct 27 ms 47228 KB Output is correct
13 Correct 19 ms 47196 KB Output is correct
14 Correct 21 ms 47192 KB Output is correct
15 Correct 25 ms 47248 KB Output is correct
16 Correct 20 ms 47164 KB Output is correct
17 Correct 27 ms 47184 KB Output is correct
18 Correct 23 ms 47152 KB Output is correct
19 Correct 26 ms 47268 KB Output is correct
20 Correct 20 ms 47184 KB Output is correct
21 Correct 19 ms 47204 KB Output is correct
22 Correct 19 ms 47240 KB Output is correct
23 Correct 21 ms 47184 KB Output is correct
24 Correct 20 ms 47236 KB Output is correct
25 Correct 19 ms 47196 KB Output is correct
26 Correct 20 ms 47176 KB Output is correct
27 Correct 19 ms 47184 KB Output is correct
28 Correct 20 ms 47184 KB Output is correct
29 Correct 21 ms 47256 KB Output is correct
30 Correct 21 ms 47184 KB Output is correct
31 Correct 21 ms 47184 KB Output is correct
32 Correct 20 ms 47196 KB Output is correct
33 Correct 20 ms 47180 KB Output is correct
34 Correct 19 ms 47244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47184 KB Output is correct
2 Correct 20 ms 47236 KB Output is correct
3 Correct 20 ms 47172 KB Output is correct
4 Correct 19 ms 47276 KB Output is correct
5 Correct 20 ms 47200 KB Output is correct
6 Correct 26 ms 47204 KB Output is correct
7 Correct 26 ms 47264 KB Output is correct
8 Correct 20 ms 47168 KB Output is correct
9 Correct 21 ms 47184 KB Output is correct
10 Correct 27 ms 47176 KB Output is correct
11 Correct 20 ms 47204 KB Output is correct
12 Correct 27 ms 47228 KB Output is correct
13 Correct 19 ms 47196 KB Output is correct
14 Correct 21 ms 47192 KB Output is correct
15 Correct 25 ms 47248 KB Output is correct
16 Correct 20 ms 47164 KB Output is correct
17 Correct 27 ms 47184 KB Output is correct
18 Correct 23 ms 47152 KB Output is correct
19 Correct 26 ms 47268 KB Output is correct
20 Correct 20 ms 47184 KB Output is correct
21 Correct 19 ms 47204 KB Output is correct
22 Correct 19 ms 47240 KB Output is correct
23 Correct 21 ms 47184 KB Output is correct
24 Correct 20 ms 47236 KB Output is correct
25 Correct 19 ms 47196 KB Output is correct
26 Correct 20 ms 47176 KB Output is correct
27 Correct 19 ms 47184 KB Output is correct
28 Correct 20 ms 47184 KB Output is correct
29 Correct 21 ms 47256 KB Output is correct
30 Correct 21 ms 47184 KB Output is correct
31 Correct 21 ms 47184 KB Output is correct
32 Correct 20 ms 47196 KB Output is correct
33 Correct 20 ms 47180 KB Output is correct
34 Correct 19 ms 47244 KB Output is correct
35 Correct 19 ms 47440 KB Output is correct
36 Correct 19 ms 47440 KB Output is correct
37 Correct 20 ms 47364 KB Output is correct
38 Correct 21 ms 47456 KB Output is correct
39 Correct 21 ms 47440 KB Output is correct
40 Correct 20 ms 47436 KB Output is correct
41 Correct 21 ms 47380 KB Output is correct
42 Correct 22 ms 47432 KB Output is correct
43 Correct 20 ms 47440 KB Output is correct
44 Correct 21 ms 47404 KB Output is correct
45 Correct 20 ms 47476 KB Output is correct
46 Correct 22 ms 47440 KB Output is correct
47 Correct 21 ms 47440 KB Output is correct
48 Correct 20 ms 47364 KB Output is correct
49 Correct 20 ms 47380 KB Output is correct
50 Correct 24 ms 47444 KB Output is correct
51 Correct 19 ms 47404 KB Output is correct
52 Correct 20 ms 47440 KB Output is correct
53 Correct 20 ms 47436 KB Output is correct
54 Correct 20 ms 47440 KB Output is correct
55 Correct 19 ms 47432 KB Output is correct
56 Correct 22 ms 47396 KB Output is correct
57 Correct 20 ms 47360 KB Output is correct
58 Correct 19 ms 47440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 47232 KB Output is correct
2 Correct 20 ms 47204 KB Output is correct
3 Correct 19 ms 47144 KB Output is correct
4 Correct 20 ms 47184 KB Output is correct
5 Correct 19 ms 47184 KB Output is correct
6 Correct 20 ms 47184 KB Output is correct
7 Correct 135 ms 145144 KB Output is correct
8 Correct 123 ms 145260 KB Output is correct
9 Correct 132 ms 145308 KB Output is correct
10 Correct 138 ms 145288 KB Output is correct
11 Correct 126 ms 145252 KB Output is correct
12 Correct 126 ms 145228 KB Output is correct
13 Correct 129 ms 145200 KB Output is correct
14 Correct 130 ms 145176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47184 KB Output is correct
2 Correct 20 ms 47236 KB Output is correct
3 Correct 20 ms 47172 KB Output is correct
4 Correct 19 ms 47276 KB Output is correct
5 Correct 20 ms 47200 KB Output is correct
6 Correct 26 ms 47204 KB Output is correct
7 Correct 26 ms 47264 KB Output is correct
8 Correct 20 ms 47168 KB Output is correct
9 Correct 21 ms 47184 KB Output is correct
10 Correct 27 ms 47176 KB Output is correct
11 Correct 20 ms 47204 KB Output is correct
12 Correct 27 ms 47228 KB Output is correct
13 Correct 19 ms 47196 KB Output is correct
14 Correct 21 ms 47192 KB Output is correct
15 Correct 25 ms 47248 KB Output is correct
16 Correct 20 ms 47164 KB Output is correct
17 Correct 27 ms 47184 KB Output is correct
18 Correct 23 ms 47152 KB Output is correct
19 Correct 26 ms 47268 KB Output is correct
20 Correct 20 ms 47184 KB Output is correct
21 Correct 19 ms 47204 KB Output is correct
22 Correct 19 ms 47240 KB Output is correct
23 Correct 21 ms 47184 KB Output is correct
24 Correct 20 ms 47236 KB Output is correct
25 Correct 19 ms 47196 KB Output is correct
26 Correct 20 ms 47176 KB Output is correct
27 Correct 19 ms 47184 KB Output is correct
28 Correct 20 ms 47184 KB Output is correct
29 Correct 21 ms 47256 KB Output is correct
30 Correct 21 ms 47184 KB Output is correct
31 Correct 21 ms 47184 KB Output is correct
32 Correct 20 ms 47196 KB Output is correct
33 Correct 20 ms 47180 KB Output is correct
34 Correct 19 ms 47244 KB Output is correct
35 Correct 19 ms 47440 KB Output is correct
36 Correct 19 ms 47440 KB Output is correct
37 Correct 20 ms 47364 KB Output is correct
38 Correct 21 ms 47456 KB Output is correct
39 Correct 21 ms 47440 KB Output is correct
40 Correct 20 ms 47436 KB Output is correct
41 Correct 21 ms 47380 KB Output is correct
42 Correct 22 ms 47432 KB Output is correct
43 Correct 20 ms 47440 KB Output is correct
44 Correct 21 ms 47404 KB Output is correct
45 Correct 20 ms 47476 KB Output is correct
46 Correct 22 ms 47440 KB Output is correct
47 Correct 21 ms 47440 KB Output is correct
48 Correct 20 ms 47364 KB Output is correct
49 Correct 20 ms 47380 KB Output is correct
50 Correct 24 ms 47444 KB Output is correct
51 Correct 19 ms 47404 KB Output is correct
52 Correct 20 ms 47440 KB Output is correct
53 Correct 20 ms 47436 KB Output is correct
54 Correct 20 ms 47440 KB Output is correct
55 Correct 19 ms 47432 KB Output is correct
56 Correct 22 ms 47396 KB Output is correct
57 Correct 20 ms 47360 KB Output is correct
58 Correct 19 ms 47440 KB Output is correct
59 Correct 21 ms 47232 KB Output is correct
60 Correct 20 ms 47204 KB Output is correct
61 Correct 19 ms 47144 KB Output is correct
62 Correct 20 ms 47184 KB Output is correct
63 Correct 19 ms 47184 KB Output is correct
64 Correct 20 ms 47184 KB Output is correct
65 Correct 135 ms 145144 KB Output is correct
66 Correct 123 ms 145260 KB Output is correct
67 Correct 132 ms 145308 KB Output is correct
68 Correct 138 ms 145288 KB Output is correct
69 Correct 126 ms 145252 KB Output is correct
70 Correct 126 ms 145228 KB Output is correct
71 Correct 129 ms 145200 KB Output is correct
72 Correct 130 ms 145176 KB Output is correct
73 Correct 133 ms 145252 KB Output is correct
74 Correct 131 ms 145184 KB Output is correct
75 Correct 137 ms 145252 KB Output is correct
76 Correct 141 ms 145376 KB Output is correct
77 Correct 131 ms 145248 KB Output is correct
78 Correct 131 ms 145172 KB Output is correct
79 Correct 139 ms 145256 KB Output is correct
80 Correct 155 ms 145260 KB Output is correct
81 Correct 131 ms 145144 KB Output is correct
82 Correct 131 ms 145136 KB Output is correct
83 Correct 149 ms 145156 KB Output is correct
84 Correct 156 ms 145268 KB Output is correct
85 Correct 137 ms 145256 KB Output is correct
86 Correct 147 ms 145236 KB Output is correct
87 Correct 171 ms 145292 KB Output is correct
88 Correct 142 ms 145252 KB Output is correct
89 Correct 143 ms 145260 KB Output is correct
90 Correct 147 ms 145260 KB Output is correct
91 Correct 153 ms 145220 KB Output is correct
92 Correct 158 ms 145240 KB Output is correct
93 Correct 151 ms 145148 KB Output is correct
94 Correct 157 ms 145256 KB Output is correct
95 Correct 152 ms 145148 KB Output is correct
96 Correct 150 ms 145296 KB Output is correct
97 Correct 153 ms 145264 KB Output is correct
98 Correct 150 ms 145304 KB Output is correct
99 Correct 180 ms 145256 KB Output is correct
100 Correct 152 ms 145256 KB Output is correct
101 Correct 156 ms 145280 KB Output is correct
102 Correct 151 ms 145288 KB Output is correct