제출 #648367

#제출 시각아이디문제언어결과실행 시간메모리
648367ymmLamps (JOI19_lamps)C++17
100 / 100
65 ms27976 KiB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 1'000'010;
int dp[N][3][2];
string s, t;
int n;

void update(int i, int op, int dif)
{
	int x = dp[i][0][ '0' != t[i]] + (op != 0) + (!dif &&  '0' != t[i]);
	int y = dp[i][1][ '1' != t[i]] + (op != 1) + (!dif &&  '1' != t[i]);
	int z = dp[i][2][s[i] != t[i]] + (      0) + (!dif && s[i] != t[i]);
	dp[i+1][op][dif] = min({x, y, z});
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	cin >> n >> s >> t;
	Loop (i,0,n) {
		Loop (op,0,3) {
			Loop (dif,0,2) {
				update(i, op, dif);
			}
		}
	}
	cout << dp[n][2][0] << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...