Submission #191767

# Submission time Handle Problem Language Result Execution time Memory
191767 2020-01-15T04:07:17 Z FieryPhoenix Unscrambling a Messy Bug (IOI16_messy) C++11
100 / 100
10 ms 632 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <iomanip>
#include <deque>
#include <cassert>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <chrono>
#include <ctime>
#include <random>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <iterator>
#include <climits>
#include "messy.h"
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
#define INF 2001001001
#define MOD 1000000007

int ans[100001];
int N;

bool contains(int x, vector<int>v){
  for (int y:v)
    if (y==x)
      return true;
  return false;
}

void ask(int l, int r){
  if (l>=r)
    return;
  for (int i=l;i<=(l+r)/2;i++){
    string s="";
    for (int j=0;j<N;j++)
      if (j<l || j>r)
	s+='1';
      else if (j==i)
	s+='1';
      else
	s+='0';
    add_element(s);
  }
  ask(l,(l+r)/2);
  ask((l+r)/2+1,r);
}

void solve(int l, int r, vector<int>v){
  string base="";
  for (int i=0;i<N;i++)
    base+='1';
  for (int x:v)
    base[x]='0';
  vector<int>v2,v3;
  for (int i=l;i<=r;i++){
    string s=base;
    s[v[i-l]]='1';
    bool b=check_element(s);
    if (b)
      v2.push_back(v[i-l]);
  }
  for (int i=l;i<=r;i++)
    if (!contains(v[i-l],v2))
      v3.push_back(v[i-l]);
  if (l+1==r){
    ans[v2[0]]=l;
    ans[v3[0]]=r;
    return;
  }
  solve(l,(l+r)/2,v2);
  solve((l+r)/2+1,r,v3);
}

vector<int> restore_permutation(int n, int w, int r){
  N=n;
  ask(0,n-1);
  compile_set();
  vector<int>v;
  for (int i=0;i<n;i++)
    v.push_back(i);
  solve(0,n-1,v);
  vector<int>ret;
  for (int i=0;i<n;i++)
    ret.push_back(ans[i]);
  return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB n = 8
2 Correct 2 ms 256 KB n = 8
3 Correct 2 ms 376 KB n = 8
4 Correct 2 ms 376 KB n = 8
5 Correct 3 ms 380 KB n = 8
6 Correct 3 ms 376 KB n = 8
7 Correct 2 ms 376 KB n = 8
8 Correct 3 ms 376 KB n = 8
9 Correct 2 ms 376 KB n = 8
10 Correct 2 ms 376 KB n = 8
11 Correct 3 ms 376 KB n = 8
12 Correct 2 ms 376 KB n = 8
13 Correct 2 ms 376 KB n = 8
14 Correct 2 ms 292 KB n = 8
15 Correct 2 ms 376 KB n = 8
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB n = 32
2 Correct 1 ms 376 KB n = 32
3 Correct 2 ms 376 KB n = 32
4 Correct 0 ms 376 KB n = 32
5 Correct 1 ms 376 KB n = 32
6 Correct 2 ms 376 KB n = 32
7 Correct 2 ms 404 KB n = 32
8 Correct 1 ms 376 KB n = 32
9 Correct 2 ms 376 KB n = 32
10 Correct 5 ms 380 KB n = 32
11 Correct 1 ms 404 KB n = 32
12 Correct 2 ms 380 KB n = 32
13 Correct 3 ms 376 KB n = 32
14 Correct 3 ms 376 KB n = 32
15 Correct 3 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 3 ms 376 KB n = 32
4 Correct 3 ms 376 KB n = 32
5 Correct 3 ms 376 KB n = 32
6 Correct 3 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 348 KB n = 32
10 Correct 2 ms 376 KB n = 32
11 Correct 2 ms 376 KB n = 32
12 Correct 3 ms 376 KB n = 32
13 Correct 2 ms 376 KB n = 32
14 Correct 2 ms 424 KB n = 32
15 Correct 2 ms 376 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 5 ms 504 KB n = 128
2 Correct 4 ms 504 KB n = 128
3 Correct 5 ms 632 KB n = 128
4 Correct 5 ms 504 KB n = 128
5 Correct 5 ms 504 KB n = 128
6 Correct 4 ms 476 KB n = 128
7 Correct 5 ms 504 KB n = 128
8 Correct 3 ms 504 KB n = 128
9 Correct 5 ms 508 KB n = 128
10 Correct 5 ms 504 KB n = 128
11 Correct 4 ms 504 KB n = 128
12 Correct 5 ms 504 KB n = 128
13 Correct 5 ms 504 KB n = 128
14 Correct 5 ms 504 KB n = 128
15 Correct 4 ms 504 KB n = 128
# Verdict Execution time Memory Grader output
1 Correct 4 ms 476 KB n = 128
2 Correct 5 ms 632 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 5 ms 632 KB n = 128
12 Correct 5 ms 504 KB n = 128
13 Correct 10 ms 504 KB n = 128
14 Correct 4 ms 536 KB n = 128
15 Correct 4 ms 504 KB n = 128