Submission #171320

# Submission time Handle Problem Language Result Execution time Memory
171320 2019-12-28T10:51:51 Z gs18103 Lamps (JOI19_lamps) C++14
100 / 100
35 ms 16328 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define em emplace
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int MAX = 1010101;
const int INF = 1e9;
const ll LINF = 1e18;

int dp[3][MAX];

int main() {
    ios::sync_with_stdio(false); cin.tie(0);

    int n;
    string s, t;
    cin >> n >> s >> t;
    dp[0][0] = 1 + (t[0] == '1');
    dp[1][0] = 1 + (t[0] == '0');
    dp[2][0] = 0 + (s[0] != t[0]);
    for(int i = 1; i < n; i++) {
        bool b = (t[i] == '1');
        dp[0][i] = min(dp[0][i-1] + (b && t[i-1] == '0'), 
                dp[2][i-1] + 1 + (b && s[i-1] == t[i-1]));
        dp[1][i] = min(dp[1][i-1] + (!b && t[i-1] == '1'), 
                dp[2][i-1] + 1 + (!b && s[i-1] == t[i-1]));
        dp[2][i] = min({
            dp[0][i-1] + (s[i] != t[i] && t[i-1] == '0'), 
            dp[1][i-1] + (s[i] != t[i] && t[i-1] == '1'), 
            dp[2][i-1] + (s[i] != t[i] && t[i-1] == s[i-1])
        });
    }
    cout << min({dp[0][n-1], dp[1][n-1], dp[2][n-1]});
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 388 KB Output is correct
12 Correct 4 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 4 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 1 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 380 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 416 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 3 ms 424 KB Output is correct
33 Correct 2 ms 380 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 388 KB Output is correct
12 Correct 4 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 4 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 1 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 380 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 416 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 3 ms 424 KB Output is correct
33 Correct 2 ms 380 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 8 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 380 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 376 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 376 KB Output is correct
54 Correct 2 ms 376 KB Output is correct
55 Correct 2 ms 376 KB Output is correct
56 Correct 4 ms 416 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 24 ms 16188 KB Output is correct
8 Correct 26 ms 16140 KB Output is correct
9 Correct 24 ms 16148 KB Output is correct
10 Correct 27 ms 16176 KB Output is correct
11 Correct 26 ms 16200 KB Output is correct
12 Correct 27 ms 16172 KB Output is correct
13 Correct 27 ms 16200 KB Output is correct
14 Correct 26 ms 16204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 388 KB Output is correct
12 Correct 4 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 4 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 1 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 380 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 416 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 3 ms 424 KB Output is correct
33 Correct 2 ms 380 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 8 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 380 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 376 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 376 KB Output is correct
54 Correct 2 ms 376 KB Output is correct
55 Correct 2 ms 376 KB Output is correct
56 Correct 4 ms 416 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
59 Correct 2 ms 380 KB Output is correct
60 Correct 2 ms 376 KB Output is correct
61 Correct 2 ms 376 KB Output is correct
62 Correct 2 ms 376 KB Output is correct
63 Correct 2 ms 376 KB Output is correct
64 Correct 3 ms 376 KB Output is correct
65 Correct 24 ms 16188 KB Output is correct
66 Correct 26 ms 16140 KB Output is correct
67 Correct 24 ms 16148 KB Output is correct
68 Correct 27 ms 16176 KB Output is correct
69 Correct 26 ms 16200 KB Output is correct
70 Correct 27 ms 16172 KB Output is correct
71 Correct 27 ms 16200 KB Output is correct
72 Correct 26 ms 16204 KB Output is correct
73 Correct 25 ms 16140 KB Output is correct
74 Correct 25 ms 16200 KB Output is correct
75 Correct 27 ms 16200 KB Output is correct
76 Correct 29 ms 16076 KB Output is correct
77 Correct 24 ms 16204 KB Output is correct
78 Correct 26 ms 16196 KB Output is correct
79 Correct 23 ms 16192 KB Output is correct
80 Correct 24 ms 16092 KB Output is correct
81 Correct 24 ms 16168 KB Output is correct
82 Correct 25 ms 16172 KB Output is correct
83 Correct 28 ms 16200 KB Output is correct
84 Correct 30 ms 16200 KB Output is correct
85 Correct 29 ms 16076 KB Output is correct
86 Correct 29 ms 16328 KB Output is correct
87 Correct 28 ms 16176 KB Output is correct
88 Correct 27 ms 16100 KB Output is correct
89 Correct 34 ms 16176 KB Output is correct
90 Correct 28 ms 16220 KB Output is correct
91 Correct 30 ms 16200 KB Output is correct
92 Correct 32 ms 16200 KB Output is correct
93 Correct 32 ms 16196 KB Output is correct
94 Correct 33 ms 16196 KB Output is correct
95 Correct 33 ms 16200 KB Output is correct
96 Correct 35 ms 16204 KB Output is correct
97 Correct 32 ms 16196 KB Output is correct
98 Correct 35 ms 16172 KB Output is correct
99 Correct 35 ms 16200 KB Output is correct
100 Correct 33 ms 16204 KB Output is correct
101 Correct 32 ms 16204 KB Output is correct
102 Correct 32 ms 16148 KB Output is correct