Submission #445749

#TimeUsernameProblemLanguageResultExecution timeMemory
445749egod1537Lamps (JOI19_lamps)C++14
100 / 100
57 ms2848 KiB
#include <bits/stdc++.h>

using namespace std;

string A, B;
int dp[2][3];

char apply(char a, int y) {
	return (y == 0) ? '0' : (y == 1) ? '1' : a;
}

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

	int n; cin >> n;
	cin >> A >> B;

	memset(dp, 0x3f3f3f3f, sizeof(dp));

	dp[0][2] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) dp[(i + 1) % 2][j] = 0x3f3f3f3f;
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				int cot = dp[i%2][j];
				if (j != k && k != 2) cot++;
				if ((i == 0 || apply(A[i - 1], j) == B[i - 1]) &&
					apply(A[i], k) != B[i])
					++cot;
				dp[(i+1)%2][k] = min(dp[(i+1)%2][k], cot);
			}
		}
	}

	cout << min({ dp[n%2][0], dp[n%2][1], dp[n%2][2] });

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...