# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
384794 |
2021-04-02T09:42:21 Z |
kostia244 |
Lamps (JOI19_lamps) |
C++17 |
|
60 ms |
26044 KB |
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 12;
int dp[maxn][3][2];
void minq(int &a, int b) {
a = min(a, b);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
string a, b;
cin >> n >> a >> b;
memset(dp, 0x3f, sizeof dp);
dp[0][0][0] = 0;
for(int i = 0; i < n; i++) {
for(int lst = 0; lst < 3; lst++) {
dp[i][lst][0] = min(dp[i][lst][0], dp[i][lst][1]);
dp[i][lst][1] = min(dp[i][lst][1], dp[i][lst][0]+1);
for(int rev = 0; rev < 2; rev++) {
int cur = (a[i]-'0')^rev;
int targ = b[i]-'0';
if((cur == targ && !lst) || lst-1 == targ)
minq(dp[i+1][lst][rev], dp[i][lst][rev]);
if(cur == targ)
minq(dp[i+1][0][rev], dp[i][lst][rev]);
minq(dp[i+1][1+targ][rev], dp[i][lst][rev]+1);
}
}
}
int ans = 69<<20;
for(int i = 0; i < 3; i++)
for(int j = 0; j < 2; j++)
ans = min(dp[n][i][j], ans);
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23788 KB |
Output is correct |
2 |
Correct |
14 ms |
23788 KB |
Output is correct |
3 |
Correct |
15 ms |
23916 KB |
Output is correct |
4 |
Correct |
14 ms |
23788 KB |
Output is correct |
5 |
Correct |
14 ms |
23788 KB |
Output is correct |
6 |
Correct |
15 ms |
23788 KB |
Output is correct |
7 |
Correct |
14 ms |
23788 KB |
Output is correct |
8 |
Correct |
14 ms |
23788 KB |
Output is correct |
9 |
Correct |
15 ms |
23788 KB |
Output is correct |
10 |
Correct |
14 ms |
23788 KB |
Output is correct |
11 |
Correct |
16 ms |
23788 KB |
Output is correct |
12 |
Correct |
14 ms |
23788 KB |
Output is correct |
13 |
Correct |
14 ms |
23788 KB |
Output is correct |
14 |
Correct |
14 ms |
23788 KB |
Output is correct |
15 |
Correct |
17 ms |
23788 KB |
Output is correct |
16 |
Incorrect |
14 ms |
23788 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23788 KB |
Output is correct |
2 |
Correct |
14 ms |
23788 KB |
Output is correct |
3 |
Correct |
15 ms |
23916 KB |
Output is correct |
4 |
Correct |
14 ms |
23788 KB |
Output is correct |
5 |
Correct |
14 ms |
23788 KB |
Output is correct |
6 |
Correct |
15 ms |
23788 KB |
Output is correct |
7 |
Correct |
14 ms |
23788 KB |
Output is correct |
8 |
Correct |
14 ms |
23788 KB |
Output is correct |
9 |
Correct |
15 ms |
23788 KB |
Output is correct |
10 |
Correct |
14 ms |
23788 KB |
Output is correct |
11 |
Correct |
16 ms |
23788 KB |
Output is correct |
12 |
Correct |
14 ms |
23788 KB |
Output is correct |
13 |
Correct |
14 ms |
23788 KB |
Output is correct |
14 |
Correct |
14 ms |
23788 KB |
Output is correct |
15 |
Correct |
17 ms |
23788 KB |
Output is correct |
16 |
Incorrect |
14 ms |
23788 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23788 KB |
Output is correct |
2 |
Correct |
14 ms |
23788 KB |
Output is correct |
3 |
Correct |
15 ms |
23788 KB |
Output is correct |
4 |
Correct |
14 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23788 KB |
Output is correct |
7 |
Correct |
59 ms |
25916 KB |
Output is correct |
8 |
Correct |
60 ms |
26044 KB |
Output is correct |
9 |
Correct |
59 ms |
25916 KB |
Output is correct |
10 |
Correct |
60 ms |
26044 KB |
Output is correct |
11 |
Correct |
59 ms |
25916 KB |
Output is correct |
12 |
Correct |
59 ms |
25916 KB |
Output is correct |
13 |
Correct |
59 ms |
25916 KB |
Output is correct |
14 |
Correct |
59 ms |
25916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23788 KB |
Output is correct |
2 |
Correct |
14 ms |
23788 KB |
Output is correct |
3 |
Correct |
15 ms |
23916 KB |
Output is correct |
4 |
Correct |
14 ms |
23788 KB |
Output is correct |
5 |
Correct |
14 ms |
23788 KB |
Output is correct |
6 |
Correct |
15 ms |
23788 KB |
Output is correct |
7 |
Correct |
14 ms |
23788 KB |
Output is correct |
8 |
Correct |
14 ms |
23788 KB |
Output is correct |
9 |
Correct |
15 ms |
23788 KB |
Output is correct |
10 |
Correct |
14 ms |
23788 KB |
Output is correct |
11 |
Correct |
16 ms |
23788 KB |
Output is correct |
12 |
Correct |
14 ms |
23788 KB |
Output is correct |
13 |
Correct |
14 ms |
23788 KB |
Output is correct |
14 |
Correct |
14 ms |
23788 KB |
Output is correct |
15 |
Correct |
17 ms |
23788 KB |
Output is correct |
16 |
Incorrect |
14 ms |
23788 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |