Submission #874004

#TimeUsernameProblemLanguageResultExecution timeMemory
874004vjudge1Lamps (JOI19_lamps)C++17
0 / 100
1034 ms9136 KiB
#include <bits/stdc++.h> #define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout); #define fast_io ios::sync_with_stdio(false);cin.tie(0); #define what(x) cerr << #x << " is " << x << '\n'; #define kill(x) {cout << x << '\n'; return 0;} #define all(x) (x).begin(), (x).end() #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define ll long long #define F first #define S second const ll inf = 1e18, mod = 1e9 + 7, delta = 1e9 + 9, SQ = 450, P = 6065621; //998244353 using namespace std; const ll N = 1e6 + 10, LG = 20; int n, dis[N]; queue<ll> q; bool mark[N]; int main() { fast_io; string x, y; cin >> n >> x >> y; ll a = 0, b = 0; for (int i = n - 1, j = 0; i >= 0; i--, j++) a += (x[i] == '1') * (1 << j); for (int i = n - 1, j = 0; i >= 0; i--, j++) b += (y[i] == '1') * (1 << j); q.push(a); memset(dis, 63, sizeof dis); dis[a] = 0; mark[a] = true; if (a == b) kill(0); while (q.size()) { int v = q.front(); q.pop(); for (int i = 0; i < n; i++) for (int j = i; j < n; j++) { int x = v; for (int k = i; k <= j; k++) if (x & (1 << k)) x ^= (1 << k); if (!mark[x]) { mark[x] = true; q.push(x); dis[x] = dis[v] + 1; if (x == b) goto Hell; } } for (int i = 0; i < n; i++) for (int j = i; j < n; j++) { int x = v; for (int k = i; k <= j; k++) if (!(x & (1 << k))) x ^= (1 << k); if (!mark[x]) { mark[x] = true; q.push(x); dis[x] = dis[v] + 1; if (x == b) goto Hell; } } for (int i = 0; i < n; i++) for (int j = i; j < n; j++) { int x = v; for (int k = i; k <= j; k++) x ^= (1 << k); if (!mark[x]) { mark[x] = true; q.push(x); dis[x] = dis[v] + 1; if (x == b) goto Hell; } } } Hell:; cout << dis[b] << '\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...