Submission #1247649

#TimeUsernameProblemLanguageResultExecution timeMemory
1247649julia_08Unscrambling a Messy Bug (IOI16_messy)C++20
38 / 100
1 ms328 KiB
#include <bits/stdc++.h>
#include "messy.h"

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 128;

int to[MAXN], marc[MAXN];

vector<int> restore_permutation(int n, int w, int r){

  string s; 

  for(int i=0; i<n; i++) s.push_back('0');

  for(int i=0; i<n; i++){
    s[n - 1 - i] = '1';
    add_element(s);
  }

  compile_set();

  vector<int> ans(n);

  string cur;

  for(int i=0; i<n; i++) cur.push_back('0');

  vector<int> v;

  for(int i=0; i<n; i++) v.push_back(i);

  for(int i=0; i<n; i++){

    bool ok = false;

    for(int k=0; k<v.size(); k++){

      int j = v[k];
      if(j != i) continue;

      cur[n - 1 - j] = '1';

      if(check_element(cur)){

        to[n - 1 - i] = n - 1 - j;
        marc[j] = 1;
          
        swap(v[k], v.back());
        v.pop_back();

        ok = true;
        break; 

      } else cur[n - 1 - j] = '0';

    }

    if(ok) continue;

    shuffle(v.begin(), v.end(), rng);

    for(int k=0; k<v.size(); k++){

      int j = v[k];

      cur[n - 1 - j] = '1';
      if(check_element(cur)){

        to[n - 1 - i] = n - 1 - j;
        marc[j] = 1;
          
        swap(v[k], v.back());
        v.pop_back();

        break; 

      } else cur[n - 1 - j] = '0';

    }

  }

  for(int i=0; i<n; i++) ans[to[i]] = i;

  return ans;

}

Compilation message (stderr)

messy.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
messy_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...