# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1101209 |
2024-10-15T18:13:01 Z |
raduv |
Mouse (info1cup19_mouse) |
C++17 |
|
1 ms |
336 KB |
#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 |
1 |
Runtime error |
1 ms |
336 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
336 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
336 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |