Submission #104612

#TimeUsernameProblemLanguageResultExecution timeMemory
104612antimirageLamps (JOI19_lamps)C++14
0 / 100
1079 ms263168 KiB
# include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n, u[N], sz; string a, b, s; queue <int> q; unordered_map <string, int> asd; inline int f (string S){ return asd[S]; } inline string F (int v){ string cur; for (int i = 0; i < n; i++){ if ( v & (1 << i) ) cur = '1' + cur; else cur = '0' + cur; } return cur; } void dfs (int pos){ if (pos == n) { int cur = 0, j = 0; for (int i = s.size() - 1; i >= 0; i--) { if (s[i] == '1') cur += (1 << j); j++; } asd[s] = cur; return; } s += '0'; dfs(pos + 1); s.pop_back(); s += '1'; dfs(pos + 1); s.pop_back(); } int main(){ cin >> n; cin >> a >> b; dfs(0); u[ f(a) ] = 1; q.push( f(a) ); while (!q.empty()){ int v = q.front(); q.pop(); a = F(v); for (int i = 0; i < n; i++){ s = a; for (int j = i; j < n; j++){ a[j] = '1'; if ( u[ f(a) ] == 0 ){ u[ f(a) ] = u[v] + 1; q.push( f(a) ); } } a = s; } for (int i = 0; i < n; i++){ s = a; for (int j = i; j < n; j++){ a[j] = '0'; if ( u[ f(a) ] == 0 ){ u[ f(a) ] = u[v] + 1; q.push( f(a) ); } } a = s; } for (int i = 0; i < n; i++){ s = a; for (int j = i; j < n; j++){ a[j] = (a[j] == '0' ? '1' : '0'); if ( u[ f(a) ] == 0 ){ u[ f(a) ] = u[v] + 1; q.push( f(a) ); } } a = s; } } cout << u[ f(b) ] - 1 << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...