제출 #485427

#제출 시각아이디문제언어결과실행 시간메모리
485427cheissmartLamps (JOI19_lamps)C++14
100 / 100
54 ms6312 KiB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
	cerr << to_string(h);
	if(sizeof ...(t)) cerr << ", ";
	DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;

	int n;
	string s, t;
	cin >> n >> s >> t;
	s = '0' + s, t = '0' + t;
	vi dp{0, INF, INF};
	// nothing, change to 0, change to 1
	for(int i = 1; i <= n; i++) {
		vi ndp{INF, INF, INF};
		for(int j = 0; j < 3; j++) {
			int ps = j == 0 ? s[i - 1] - '0' : j - 1, pt = t[i - 1] - '0';
			for(int k = 0; k < 3; k++) {
				int ns = k == 0 ? s[i] - '0' : k - 1, nt = t[i] - '0';
				int cost = 0;
				if(k && k != j) cost++;
				if((ps ^ pt) == 0 && (ns ^ nt) == 1)
					cost++;
				ndp[k] = min(ndp[k], dp[j] + cost);
			}
		}
		swap(dp, ndp);
	}
	cout << *min_element(ALL(dp)) << '\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...