# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
623828 |
2022-08-06T15:17:20 Z |
Arnch |
Lamps (JOI19_lamps) |
C++17 |
|
48 ms |
35188 KB |
// oooo
/*
har chi delet mikhad bebar ~
gitar o ba khodet nabar! ~
;Amoo_Hasan;
*/
#include<bits/stdc++.h>
//#pragma GCC optimize("O3,no-stack-protector,unroll-loops")
//#pragma GCC target("avx2,fma")
using namespace std;
typedef long long ll;
typedef long double ld;
#define Sz(x) int((x).size())
#define All(x) (x).begin(), (x).end()
#define wtf(x) cout<<#x <<" : " <<x <<endl
constexpr ll inf = 1e18, N = 1e6 + 10, mod = 1e9 + 7, pr = 1000696969;
ll dp[N][3];
int A[N], B[N];
int main() {
ios :: sync_with_stdio(0), cin.tie(0);
int n; cin >>n;
string a, b; cin >>a >>b;
for(int i = 0; i < n; i++) {
A[i + 1] = (a[i] - '0') + 1;
B[i + 1] = (b[i] - '0') + 1;
}
memset(dp, 63, sizeof(dp));
dp[0][0] = 0;
for(int i = 1; i <= n; i++) {
for(int j = 0; j < 3; j++) {
for(int k = 0; k < 3; k++) {
if(j != 0 && j == k) {
if(j == B[i - 1] && j != B[i]) {
dp[i][j] = min(dp[i][j], dp[i - 1][k] + 2);
continue;
}
dp[i][j] = min(dp[i][j], dp[i - 1][k]);
continue;
}
if(j == 0) {
if(k == 0) {
if(A[i] != B[i] && A[i - 1] == B[i - 1]) {
dp[i][j] = min(dp[i][j], dp[i - 1][k] + 2);
continue;
}
dp[i][j] = min(dp[i][j], dp[i - 1][k]);
continue;
}
if(A[i] != B[i] && B[i - 1] == k) {
dp[i][j] = min(dp[i][j], dp[i - 1][k] + 2);
continue;
}
dp[i][j] = min(dp[i][j], dp[i - 1][k]);
}
if(k == B[i - 1] && j != B[i]) {
dp[i][j] = min(dp[i][j], dp[i - 1][k] + 4);
continue;
}
dp[i][j] = min(dp[i][j], dp[i - 1][k] + 2);
continue;
}
}
}
/*for(int i = 1; i <= n; i++) {
for(int j = 0; j < 3; j++) {
cout<<"^^" <<i <<" " <<j <<" " <<dp[i][j] / 2 <<endl;
}
}*/
ll ans = inf;
for(int i = 0; i < 3; i++) ans = min(ans, dp[n][i]);
cout<<ans / 2;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
23764 KB |
Output is correct |
2 |
Correct |
10 ms |
23764 KB |
Output is correct |
3 |
Correct |
10 ms |
23764 KB |
Output is correct |
4 |
Correct |
10 ms |
23708 KB |
Output is correct |
5 |
Correct |
10 ms |
23740 KB |
Output is correct |
6 |
Correct |
9 ms |
23748 KB |
Output is correct |
7 |
Correct |
10 ms |
23764 KB |
Output is correct |
8 |
Correct |
10 ms |
23764 KB |
Output is correct |
9 |
Correct |
10 ms |
23776 KB |
Output is correct |
10 |
Correct |
12 ms |
23736 KB |
Output is correct |
11 |
Correct |
10 ms |
23764 KB |
Output is correct |
12 |
Incorrect |
10 ms |
23764 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
23764 KB |
Output is correct |
2 |
Correct |
10 ms |
23764 KB |
Output is correct |
3 |
Correct |
10 ms |
23764 KB |
Output is correct |
4 |
Correct |
10 ms |
23708 KB |
Output is correct |
5 |
Correct |
10 ms |
23740 KB |
Output is correct |
6 |
Correct |
9 ms |
23748 KB |
Output is correct |
7 |
Correct |
10 ms |
23764 KB |
Output is correct |
8 |
Correct |
10 ms |
23764 KB |
Output is correct |
9 |
Correct |
10 ms |
23776 KB |
Output is correct |
10 |
Correct |
12 ms |
23736 KB |
Output is correct |
11 |
Correct |
10 ms |
23764 KB |
Output is correct |
12 |
Incorrect |
10 ms |
23764 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
23764 KB |
Output is correct |
2 |
Correct |
10 ms |
23768 KB |
Output is correct |
3 |
Correct |
10 ms |
23756 KB |
Output is correct |
4 |
Correct |
10 ms |
23764 KB |
Output is correct |
5 |
Correct |
10 ms |
23756 KB |
Output is correct |
6 |
Correct |
10 ms |
23764 KB |
Output is correct |
7 |
Correct |
43 ms |
34624 KB |
Output is correct |
8 |
Correct |
44 ms |
35124 KB |
Output is correct |
9 |
Correct |
44 ms |
35188 KB |
Output is correct |
10 |
Correct |
44 ms |
35104 KB |
Output is correct |
11 |
Correct |
46 ms |
35012 KB |
Output is correct |
12 |
Correct |
48 ms |
35128 KB |
Output is correct |
13 |
Correct |
47 ms |
35028 KB |
Output is correct |
14 |
Correct |
43 ms |
35112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
23764 KB |
Output is correct |
2 |
Correct |
10 ms |
23764 KB |
Output is correct |
3 |
Correct |
10 ms |
23764 KB |
Output is correct |
4 |
Correct |
10 ms |
23708 KB |
Output is correct |
5 |
Correct |
10 ms |
23740 KB |
Output is correct |
6 |
Correct |
9 ms |
23748 KB |
Output is correct |
7 |
Correct |
10 ms |
23764 KB |
Output is correct |
8 |
Correct |
10 ms |
23764 KB |
Output is correct |
9 |
Correct |
10 ms |
23776 KB |
Output is correct |
10 |
Correct |
12 ms |
23736 KB |
Output is correct |
11 |
Correct |
10 ms |
23764 KB |
Output is correct |
12 |
Incorrect |
10 ms |
23764 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |