답안 #104612

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104612 2019-04-08T11:09:16 Z antimirage Lamps (JOI19_lamps) C++14
0 / 100
1000 ms 263168 KB
# 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Execution timed out 1079 ms 29788 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Execution timed out 1079 ms 29788 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Runtime error 554 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Execution timed out 1079 ms 29788 KB Time limit exceeded
9 Halted 0 ms 0 KB -