제출 #562655

#제출 시각아이디문제언어결과실행 시간메모리
562655aryan12Lamps (JOI19_lamps)C++17
47 / 100
25 ms17720 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 5, INF = 1e14;
vector<vector<int> > dp(N, vector<int> (3, INF));

// 0 - OFF
// 1 - ON
// 2 - UNUSED

char getvalue(char a, int x)
{
	if(x == 0) return '0';
	if(x == 1) return '1';
	return a;
}

void Solve() 
{
	int n;
	cin >> n;
	string a, b;
	cin >> a >> b;
	dp[0][2] = 0;
	for(int i = 1; i <= n; i++)
	{
		// cout << "i = " << i << endl;
		char cur_a = a[i - 1], cur_b = b[i - 1];
		for(int j = 0; j < 3; j++)
		{
			for(int k = 0; k < 3; k++)
			{
				int value = dp[i - 1][k];
				// if the last value had an operation and the current value has a diff / no operation
				if(j != k && j != 2)
				{
					value++;
				}
				// if the answer after the operation is not consistent with b[i]
				if((i == 1 || getvalue(a[i - 2], k) == b[i - 2]) && getvalue(cur_a, j) != cur_b)
				{
					value++;
				}
				dp[i][j] = min(dp[i][j], value);
			}
		}
	}
	// for(int i = 0; i <= n; i++)
	// {
	// 	for(int j = 0; j < 3; j++)
	// 	{
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << "\n";
	// }
	int ans = INF;
	for(int i = 0; i < 3; i++)
	{
		ans = min(ans, dp[n][i]);
	}
	cout << ans << "\n";
}

int32_t main() 
{
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++) 
	{
		//cout << "Case #" << i << ": ";
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	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...