Submission #376193

#TimeUsernameProblemLanguageResultExecution timeMemory
376193wiwihoLamps (JOI19_lamps)C++14
6 / 100
464 ms4796 KiB
#include <bits/stdc++.h> #define eb emplace_back #define printv(a, b) { \ for(auto pv : a) b << pv << " "; \ b << "\n"; \ } using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n; string sa, sb; cin >> n >> sa >> sb; assert(n <= 18); int a = bitset<20>(sa).to_ulong(), b = bitset<20>(sb).to_ulong(); vector<int> dis(1 << n, -1); queue<int> q; q.push(a); dis[a] = 0; while(!q.empty()){ int now = q.front(); q.pop(); for(int j = 0; j < n; j++){ int tmp = now; for(int k = j; k < n; k++){ tmp ^= 1 << k; if(dis[tmp] == -1){ dis[tmp] = dis[now] + 1; q.push(tmp); } } } for(int j = 0; j < n; j++){ int tmp = now; for(int k = j; k < n; k++){ tmp |= 1 << k; if(dis[tmp] == -1){ dis[tmp] = dis[now] + 1; q.push(tmp); } } } for(int j = 0; j < n; j++){ int tmp = now; for(int k = j; k < n; k++){ if(1 << k & tmp) tmp ^= 1 << k; if(dis[tmp] == -1){ dis[tmp] = dis[now] + 1; q.push(tmp); } } } } 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...