This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <set>
#include <vector>
//#define DEBUG
//#define PRINTQ
#ifndef DEBUG
#include "grader.h"
#endif // DEBUG
const int MAXN = 256;
std::set<int> candidates[MAXN + 1];
std::set<int> available, cavailable;
#ifdef DEBUG
int p[MAXN + 1];
int n;
#endif // DEBUG
int order_of_key(std::set<int> st, int poz){
auto it = st.begin();
for( int i = 1; i <= poz; i++ )
it++;
return *it;
}
#ifdef DEBUG
int query(std::vector<int> q){
#ifdef PRINTQ
printf("%d ", q.size());
for(auto x : q)
printf("%d ", x);
printf("\n");
#endif // PRINTQ
int x = 0;
for( int i = 0; i < n; i++ ){
if(q[i] == p[i])
x++;
}
return x;
}
#endif // DEBUG
void solve(int n){
srand(time(0));
int i, j, x;
for( i = 1; i <= n; i++ ){
available.insert(i);
for( j = 1; j <= n; j++ )
candidates[i].insert(j);
}
std::vector<int> q(n);
for( i = 1; i <= n; i++ ){
while(candidates[i].size() > 1){
q[i - 1] = order_of_key(candidates[i], rand() % candidates[i].size());
cavailable = available;
available.erase(q[i - 1]);
for( j = i + 1; j <= n; j++ ){
q[j - 1] = order_of_key(available, rand() % available.size());
available.erase(q[j - 1]);
}
available = cavailable;
#ifdef DEBUG
printf("available : ");
for( auto x : available )
printf("%d ", x);
printf("\n");
#endif // DEBUG
if( (x = query(q)) == i - 1 ){
for( j = i; j <= n; j++ ){
if(candidates[j].find(q[j - 1]) != candidates[j].end())
candidates[j].erase(q[j - 1]);
}
}
else if(x == n)
return;
q[i - 1] = *candidates[i].begin();
for( j = i + 1; j <= n; j++ )
if(candidates[j].find(q[i - 1]) != candidates[j].end())
candidates[j].erase(q[i - 1]);
}
}
query(q);
}
#ifdef DEBUG
int main(){
n = 7;
p[0] = 2;
p[1] = 1;
p[2] = 3;
p[3] = 4;
solve(n);
return 0;
}
#endif // DEBUG
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |