Submission #1101220

#TimeUsernameProblemLanguageResultExecution timeMemory
1101220raduvMouse (info1cup19_mouse)C++17
Compilation error
0 ms0 KiB
#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; bool isset[MAXN + 1]; #ifdef DEBUG int p[MAXN + 1] = {66, 68, 195, 188, 194, 112, 187, 118, 175, 115, 46, 61, 14, 70, 157, 50, 135, 31, 28, 33, 109, 7, 105, 126, 13, 158, 116, 53, 93, 103, 83, 155, 148, 108, 128, 131, 100, 165, 37, 143, 79, 12, 95, 10, 104, 18, 139, 5, 3, 71, 114, 154, 27, 64, 132, 110, 49, 52, 11, 122, 170, 85, 67, 185, 177, 138, 169, 40, 189, 129, 45, 149, 142, 21, 173, 184, 4, 121, 127, 119, 22, 9, 43, 192, 107, 30, 72, 76, 172, 59, 167, 137, 89, 73, 86, 181, 178, 41, 150, 57, 125, 42, 97, 74, 62, 60, 81, 101, 117, 55, 124, 69, 77, 88, 102, 92, 168, 113, 120, 19, 133, 23, 17, 56, 65, 91, 183, 136, 63, 152, 24, 32, 196, 182, 186, 16, 106, 36, 191, 1, 8, 35, 174, 146, 84, 151, 39, 48, 144, 111, 99, 51, 29, 147, 96, 156, 130, 164, 162, 193, 180, 94, 141, 179, 54, 153, 166, 161, 26, 90, 163, 38, 78, 82, 171, 176, 159, 87, 34, 20, 6, 140, 75, 123, 145, 98, 160, 15, 47, 25, 58, 80, 190, 44, 2, 134}; int n = 196; 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, p; 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++ ){ int mn = n + 1; for( j = 1; j <= n; j++ ) if( !isset[j] && candidates[j].size() < mn ){ mn = candidates[j].size(); p = j; } isset[p] = 1; while(candidates[p].size() > 1){ q[p - 1] = order_of_key(candidates[p], rand() % candidates[p].size()); cavailable = available; available.erase(q[p - 1]); for( j = 1; j <= n; j++ ){ if(!isset[j]){ q[j - 1] = order_of_key(available, rand() % available.size()); available.erase(q[j - 1]); } } available = cavailable; #ifdef PRINTQ printf("%d available : ", p); for( auto x : available ) printf("%d ", x); printf("\n"); #endif // DEBUG if( (x = query(q)) == i - 1 ){ for( j = 1; j <= n; j++ ){ if( (!isset[j] || j == p) && candidates[j].find(q[j - 1]) != candidates[j].end()) candidates[j].erase(q[j - 1]); } } else if(x == n) return; } q[p - 1] = *candidates[p].begin(); for( j = 1; j <= n; j++ ) if(!isset[j] && candidates[j].find(q[p - 1]) != candidates[j].end()) candidates[j].erase(q[p - 1]); available.erase(*candidates[p].begin()); } ans = q; 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

Compilation message (stderr)

mouse.cpp: In function 'void solve(int)':
mouse.cpp:74:45: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   74 |       if( !isset[j] && candidates[j].size() < mn ){
      |                        ~~~~~~~~~~~~~~~~~~~~~^~~~
mouse.cpp:113:3: error: 'ans' was not declared in this scope; did you mean 'abs'?
  113 |   ans = q;
      |   ^~~
      |   abs