Submission #1259435

#TimeUsernameProblemLanguageResultExecution timeMemory
1259435minggaLamps (JOI19_lamps)C++20
100 / 100
38 ms26956 KiB
// Author: caption_mingle
#include "bits/stdc++.h"

using namespace std;

#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 1e6 + 7;
int n, f[N][3][2];
string s;
bool a[N], b[N];

signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	#define task ""
	if(fopen(task ".INP", "r")) {
		freopen(task ".INP", "r", stdin);
		freopen(task ".OUT", "w", stdout);
	}
	cin >> n;
	cin >> s;
	for(int i = 1; i <= n; i++) a[i] = (s[i - 1] - 48);
	cin >> s;
	for(int i = 1; i <= n; i++) b[i] = (s[i - 1] - 48);
	memset(f, 0x3f, sizeof f);
	f[0][0][0] = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j < 3; j++) {
			for(int k = 0; k < 2; k++) {
				int cur = a[i];
				if(j == 1) cur = 0;
				if(j == 2) cur = 1;
				cur ^= k;
				if(cur != b[i]) continue;
				for(int tj = 0; tj < 3; tj++) {
					for(int tk = 0; tk < 2; tk++) {
						f[i][j][k] = min(f[i][j][k], f[i - 1][tj][tk] + (j and j != tj) + (k and !tk));
					}
				}
			}
		}
	}
	int ans = inf;
	for(int j = 0; j < 3; j++) {
		for(int k = 0; k < 2; k++) {
			ans = min(ans, f[n][j][k]);
		}
	}
	cout << ans << ln;
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}

Compilation message (stderr)

lamp.cpp: In function 'int main()':
lamp.cpp:24:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |                 freopen(task ".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:25:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |                 freopen(task ".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...