# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
331058 | lohacho | Lamps (JOI19_lamps) | C++14 | 265 ms | 21996 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int MOD = (int)1e9 + 7;
const int NS = (int)1e6 + 4;
int N;
int A[NS], B[NS];
int dp[NS][3];
int cha(int x, int y){
if(y != 2){
return y;
}
return x;
}
int main(){
scanf("%d", &N);
for(int i = 1; i <= N; ++i){
scanf("%1d", A + i);
}
for(int i = 1; i <= N; ++i){
scanf("%1d", B + i);
}
for(int i = 0; i < NS; ++i){
for(int j = 0; j < 3; ++j){
dp[i][j] = MOD;
}
}
dp[1][2] = 0;
for(int i = 1; i <= N; ++i){
for(int last = 0; last < 3; ++last){
for(int now = 0; now < 3; ++now){
int cost = 0;
if(last != now && now != 2){
++cost;
}
if((i == 1 || cha(A[i - 1], last) == B[i - 1]) && (cha(A[i], now) != B[i])){
++cost;
}
dp[i + 1][now] = min(dp[i + 1][now], cost + dp[i][last]);
}
}
}
printf("%d", min({dp[N + 1][0], dp[N + 1][1], dp[N + 1][2]}));
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |