# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
173127 | dennisstar | Lamps (JOI19_lamps) | C++11 | 34 ms | 16084 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>
#define fi first
#define se second
#define ryan bear
#define all(V) ((V).begin()), ((V).end())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef vector<int> vim;
typedef vector<ll> vlm;
int N, D[3][1000010];
char A[1000010], B[1000010];
int main() {
scanf("%d %s %s", &N, A+1, B+1);
D[0][1] = (B[1] == '0') + 1; //changed to 0
D[1][1] = (B[1] == '1') + 1; //changed to 1
D[2][1] = (A[1] != B[1]); //reversed
for (int i=2; i<=N; i++) {
D[0][i] = min(D[0][i-1] + (B[i]=='0'&&B[i-1]=='1'), D[2][i-1] + 1 + ((B[i]=='0')&&A[i-1]==B[i-1]));
D[1][i] = min(D[1][i-1] + (B[i]=='1'&&B[i-1]=='0'), D[2][i-1] + 1 + ((B[i]=='1')&&A[i-1]==B[i-1]));
D[2][i] = min({
D[0][i-1] + (A[i]!=B[i]&&B[i-1]=='1'),
D[1][i-1] + (A[i]!=B[i]&&B[i-1]=='0'),
D[2][i-1] + (A[i]!=B[i]&&B[i-1]==A[i-1])
});
}
printf("%d\n", min({D[0][N], D[1][N], D[2][N]}));
}
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... |