Submission #104611

#TimeUsernameProblemLanguageResultExecution timeMemory
104611antimirageLamps (JOI19_lamps)C++14
0 / 100
1072 ms4180 KiB
# include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n, u[N]; string a, b, s; queue <int> q; inline int f (string S){ int cur = 0, j = 0; for (int i = S.size() - 1; i >= 0; i--) { if (S[i] == '1') cur += (1 << j); j++; } return cur; } 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; } int main(){ cin >> n; cin >> a >> b; 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...