Submission #165284

# Submission time Handle Problem Language Result Execution time Memory
165284 2019-11-26T10:49:44 Z Nightlight Unscrambling a Messy Bug (IOI16_messy) C++14
100 / 100
15 ms 508 KB
#include <bits/stdc++.h>
using namespace std;
#include "messy.h"

vector<int> ans;
int N;

void add(int l, int r){
  int mid = (l+r)>>1;
  string front(l, '1'), back(N-r-1, '1'), now;
  for(int i = l; i <=r; i++)now += "0";
  now[0] = '1';
//  cout << front << now << back << "\n";

  add_element(front + now + back);
  for(int i = 1; i <= mid-l; i++){
    swap(now[i-1], now[i]);

//    cout << front + now + back << "\n";

    add_element(front + now + back);
  }
  if(r - l > 1){
    add(l, mid);
    add(mid+1, r);
  } 
}

void ask(bitset<128> pos, int l, int r){
//  cout << l << " " << r << "\n";
  string toask(N, '0');
  for(int i = 0; i < N; i++){
    if(pos[i] == 1)toask[i] = '1';
  }
  if(r - l < 2){
    for(int i = 0; i < N;i++){
      if(pos[i] == 0){
        toask[i] = '1';
//        cout << toask << " " << check_element(toask) << "\n";
        if(check_element(toask))ans[i] = l;
        else ans[i] = r;
        toask[i] = '0';
      }
    }
    return;
  }
  bitset<128> left;
  bitset<128> right;
  left = pos; right = pos;
  for(int i = 0; i < N; i++){
    if(pos[i] == 0){
      toask[i] = '1';
//      cout << toask << " " << check_element(toask) << "\n";
      if(check_element(toask))right[i] = 1;
      else left[i] = 1;
      toask[i] = '0';
    };
  }
  int mid = (l+r)>>1;
  ask(left, l, mid);
  ask(right, mid+1, r);
}

vector<int> restore_permutation(int n, int w, int r) {
  N = n;
  ans.resize(n);
  add(0, n-1);
//  cout << "\n";
  compile_set();
  ask(0, 0, n-1);
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n = 8
2 Correct 2 ms 376 KB n = 8
3 Correct 2 ms 376 KB n = 8
4 Correct 2 ms 252 KB n = 8
5 Correct 2 ms 376 KB n = 8
6 Correct 2 ms 376 KB n = 8
7 Correct 2 ms 256 KB n = 8
8 Correct 2 ms 256 KB n = 8
9 Correct 2 ms 256 KB n = 8
10 Correct 2 ms 256 KB n = 8
11 Correct 2 ms 256 KB n = 8
12 Correct 2 ms 376 KB n = 8
13 Correct 2 ms 396 KB n = 8
14 Correct 2 ms 376 KB n = 8
15 Correct 2 ms 256 KB n = 8
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n = 32
2 Correct 2 ms 376 KB n = 32
3 Correct 2 ms 376 KB n = 32
4 Correct 2 ms 376 KB n = 32
5 Correct 2 ms 400 KB n = 32
6 Correct 2 ms 376 KB n = 32
7 Correct 2 ms 376 KB n = 32
8 Correct 2 ms 376 KB n = 32
9 Correct 2 ms 376 KB n = 32
10 Correct 2 ms 348 KB n = 32
11 Correct 2 ms 376 KB n = 32
12 Correct 2 ms 376 KB n = 32
13 Correct 2 ms 376 KB n = 32
14 Correct 2 ms 376 KB n = 32
15 Correct 2 ms 376 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n = 32
2 Correct 3 ms 376 KB n = 32
3 Correct 2 ms 376 KB n = 32
4 Correct 2 ms 376 KB n = 32
5 Correct 15 ms 372 KB n = 32
6 Correct 2 ms 376 KB n = 32
7 Correct 2 ms 376 KB n = 32
8 Correct 2 ms 376 KB n = 32
9 Correct 2 ms 376 KB n = 32
10 Correct 2 ms 376 KB n = 32
11 Correct 2 ms 376 KB n = 32
12 Correct 2 ms 376 KB n = 32
13 Correct 3 ms 296 KB n = 32
14 Correct 2 ms 356 KB n = 32
15 Correct 14 ms 376 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB n = 128
2 Correct 4 ms 504 KB n = 128
3 Correct 4 ms 504 KB n = 128
4 Correct 4 ms 504 KB n = 128
5 Correct 4 ms 504 KB n = 128
6 Correct 4 ms 504 KB n = 128
7 Correct 4 ms 504 KB n = 128
8 Correct 4 ms 508 KB n = 128
9 Correct 4 ms 504 KB n = 128
10 Correct 4 ms 504 KB n = 128
11 Correct 4 ms 504 KB n = 128
12 Correct 4 ms 504 KB n = 128
13 Correct 4 ms 504 KB n = 128
14 Correct 4 ms 504 KB n = 128
15 Correct 4 ms 504 KB n = 128
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB n = 128
2 Correct 4 ms 504 KB n = 128
3 Correct 4 ms 504 KB n = 128
4 Correct 4 ms 504 KB n = 128
5 Correct 4 ms 504 KB n = 128
6 Correct 4 ms 504 KB n = 128
7 Correct 4 ms 504 KB n = 128
8 Correct 4 ms 504 KB n = 128
9 Correct 4 ms 504 KB n = 128
10 Correct 4 ms 504 KB n = 128
11 Correct 4 ms 504 KB n = 128
12 Correct 5 ms 504 KB n = 128
13 Correct 4 ms 504 KB n = 128
14 Correct 4 ms 504 KB n = 128
15 Correct 4 ms 504 KB n = 128