Submission #104611

# Submission time Handle Problem Language Result Execution time Memory
104611 2019-04-08T11:01:58 Z antimirage Lamps (JOI19_lamps) C++14
0 / 100
1000 ms 4180 KB
# 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 time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 128 KB Output is correct
8 Execution timed out 1069 ms 1656 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 128 KB Output is correct
8 Execution timed out 1069 ms 1656 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Execution timed out 1072 ms 4180 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 128 KB Output is correct
8 Execution timed out 1069 ms 1656 KB Time limit exceeded
9 Halted 0 ms 0 KB -