# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1101213 |
2024-10-15T18:41:50 Z |
raduv |
Mouse (info1cup19_mouse) |
C++17 |
|
2772 ms |
3408 KB |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <set>
#include <vector>
#include <algorithm>
//#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] = {13, 142, 68, 65, 151, 196, 76, 16, 167, 12, 114, 197, 69, 171, 50, 24, 27, 20, 28, 166, 116, 7, 85, 200, 2, 8, 43, 149, 179, 128, 33, 80, 134, 84, 99, 6, 5, 133, 115, 55, 108, 126, 164, 3, 82, 14, 38, 205, 29, 109, 127, 78, 88, 39, 54, 112, 103, 123, 131, 158, 107, 130, 120, 42, 156, 34, 121, 21, 48, 182, 136, 194, 58, 187, 22, 192, 138, 40, 143, 19, 170, 37, 75, 163, 15, 177, 30, 97, 111, 35, 189, 89, 144, 91, 36, 180, 64, 168, 124, 31, 1, 47, 152, 113, 165, 181, 106, 193, 92, 11, 125, 135, 159, 148, 81, 67, 95, 157, 178, 201, 79, 77, 83, 206, 169, 150, 98, 25, 72, 198, 129, 175, 204, 61, 118, 104, 62, 191, 186, 162, 173, 208, 183, 202, 90, 59, 52, 4, 49, 74, 174, 110, 132, 71, 161, 44, 153, 184, 119, 86, 199, 188, 46, 139, 137, 87, 70, 56, 53, 160, 57, 141, 66, 185, 100, 122, 203, 176, 102, 105, 207, 45, 155, 190, 101, 51, 145, 17, 172, 18, 96, 140, 117, 10, 94, 23, 63, 60, 195, 41, 154, 32, 9, 73, 93, 146, 147, 26};
int n = 208;
int nq = 0;
int st1 = 1;
std::vector<int> ans;
#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 isPermutation(std::vector<int> q){
std::sort(q.begin(), q.end());
int i = 1;
for(auto x : q){
if(x != i)
return 0;
i++;
}
return 1;
}
#endif // DEBUG
#ifdef DEBUG
int query(std::vector<int> q){
#ifdef PRINTQ
for(auto x : q)
printf("%d ", x);
printf(" perm : %d", isPermutation(q));
st1 = std::min(st1, (int)isPermutation(q));
printf("\n");
#endif // PRINTQ
nq++;
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 PRINTQ
printf("%d available : ", i);
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]);
available.erase(*candidates[i].begin());
}
query(q);
}
#ifdef DEBUG
int main(){
solve(n);
int i = 0;
int st = 1;
for( auto x : ans ){
if(x != p[i])
st = 0;
i++;
}
printf("Correct Permutations : %d\n", st1);
printf("Good Last Permutation : %d\n", st);
printf("Number Of Queries : %d\n", nq);
return 0;
}
#endif // DEBUG
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 27 |
2 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 10 |
3 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 28 |
4 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 22 |
5 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 36 |
6 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 39 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 27 |
2 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 10 |
3 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 28 |
4 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 22 |
5 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 36 |
6 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 39 |
7 |
Correct |
19 ms |
336 KB |
Correct! Number of queries: 500 |
8 |
Correct |
20 ms |
336 KB |
Correct! Number of queries: 500 |
9 |
Correct |
20 ms |
336 KB |
Correct! Number of queries: 500 |
10 |
Correct |
26 ms |
504 KB |
Correct! Number of queries: 600 |
11 |
Correct |
13 ms |
336 KB |
Correct! Number of queries: 500 |
12 |
Correct |
18 ms |
336 KB |
Correct! Number of queries: 500 |
13 |
Correct |
16 ms |
336 KB |
Correct! Number of queries: 500 |
14 |
Correct |
21 ms |
336 KB |
Correct! Number of queries: 600 |
15 |
Correct |
21 ms |
336 KB |
Correct! Number of queries: 600 |
16 |
Correct |
23 ms |
336 KB |
Correct! Number of queries: 600 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 27 |
2 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 10 |
3 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 28 |
4 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 22 |
5 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 36 |
6 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 39 |
7 |
Correct |
19 ms |
336 KB |
Correct! Number of queries: 500 |
8 |
Correct |
20 ms |
336 KB |
Correct! Number of queries: 500 |
9 |
Correct |
20 ms |
336 KB |
Correct! Number of queries: 500 |
10 |
Correct |
26 ms |
504 KB |
Correct! Number of queries: 600 |
11 |
Correct |
13 ms |
336 KB |
Correct! Number of queries: 500 |
12 |
Correct |
18 ms |
336 KB |
Correct! Number of queries: 500 |
13 |
Correct |
16 ms |
336 KB |
Correct! Number of queries: 500 |
14 |
Correct |
21 ms |
336 KB |
Correct! Number of queries: 600 |
15 |
Correct |
21 ms |
336 KB |
Correct! Number of queries: 600 |
16 |
Correct |
23 ms |
336 KB |
Correct! Number of queries: 600 |
17 |
Correct |
2641 ms |
3408 KB |
Correct! Number of queries: 3900 |
18 |
Correct |
2327 ms |
3408 KB |
Correct! Number of queries: 3900 |
19 |
Correct |
2352 ms |
3152 KB |
Correct! Number of queries: 3800 |
20 |
Correct |
2717 ms |
3408 KB |
Correct! Number of queries: 4100 |
21 |
Correct |
2567 ms |
3152 KB |
Correct! Number of queries: 4000 |
22 |
Correct |
2270 ms |
3152 KB |
Correct! Number of queries: 3700 |
23 |
Correct |
2381 ms |
3152 KB |
Correct! Number of queries: 3800 |
24 |
Correct |
2623 ms |
3408 KB |
Correct! Number of queries: 3900 |
25 |
Correct |
2772 ms |
3408 KB |
Correct! Number of queries: 4100 |
26 |
Correct |
2694 ms |
3408 KB |
Correct! Number of queries: 4000 |