Submission #793325

#TimeUsernameProblemLanguageResultExecution timeMemory
793325PixelCat저울 (IOI15_scales)C++14
Compilation error
0 ms0 KiB
#ifdef NYAOWO #include "grader.cpp" #endif #include "scales.h" #include <bits/stdc++.h> #define For(i, a, b) for(int i = a; i <= b; i++) #define Forr(i, a, b) for(int i = a; i >= b; i--) #define F first #define S second #define all(x) x.begin(), x.end() #define sz(x) ((int)x.size()) #define eb emplace_back using namespace std; using LL = long long; using pii = pair<int, int>; using BS = bitset<720>; int W[] = {1, 2, 3, 4, 5, 6}; mt19937_64 rng(7456); uint64_t seed; // 0 for lightest, 1 for median, 2 for heaviest, 3 for next lightest vector<vector<int>> perm; vector<vector<int>> options; vector<BS> mask[4]; bool match(const vector<int> &ord, const vector<int> &opt, int res) { if(opt[0] == 0) { bool ok = true; For(i, 1, 3) ok = ok && (ord[opt[i]] >= ord[opt[res]]); return ok; } if(opt[0] == 2) { bool ok = true; For(i, 1, 3) ok = ok && (ord[opt[i]] <= ord[opt[res]]); return ok; } if(opt[0] == 1) { int owo = 0; For(i, 1, 3) { int dif = (ord[opt[i]] - ord[opt[res]]); if(dif < 0) owo |= 1; if(dif == 0) owo |= 2; if(dif > 0) owo |= 4; } return owo == 7; } if(opt[0] == 3) { int o[3] = {opt[1], opt[2], opt[3]}; sort(o, o + 3, [&](int x, int y){return ord[x] < ord[y];}); int idx = 0; if(ord[opt[4]] > ord[o[2]]) idx = 0; else if(ord[opt[4]] > ord[o[1]]) idx = 2; else if(ord[opt[4]] > ord[o[0]]) idx = 1; idx = o[idx]; if(idx == opt[1]) idx = 1; else if(idx == opt[2]) idx = 2; else if(idx == opt[3]) idx = 3; return idx == res; } return false; } // how many possibilities remain at most? int worstmatch(const BS &alive, const int &opt) { int mx = 0; For(res, 1, 3) { mx = max(mx, (int) (alive & mask[res][opt]).count()); } return mx; } int best_opt(const BS &alive) { int mx = 1000, idx = -1; vector<int> all_opt; For(i, 0, sz(options) - 1) all_opt.eb(i); shuffle(all(all_opt), rng); // auto start = clock(); for(auto &i:all_opt) { int k = worstmatch(alive, i); if(k < mx) { mx = k; idx = i; } } // auto stop = clock(); // cerr << fixed << setprecision(3); // cerr << "elapsed: " << (double)(stop - start) / CLOCKS_PER_SEC << "\n"; return idx; } int make_query(const vector<int> &opt) { int x = -1; if(opt[0] == 0) { x = getLightest(opt[1] + 1, opt[2] + 1, opt[3] + 1); } else if(opt[0] == 1) { x = getMedian(opt[1] + 1, opt[2] + 1, opt[3] + 1); } else if(opt[0] == 2) { x = getHeaviest(opt[1] + 1, opt[2] + 1, opt[3] + 1); } else if(opt[0] == 3) { x = getNextLightest(opt[1] + 1, opt[2] + 1, opt[3] + 1, opt[4] + 1); } For(i, 1, 3) if(x == opt[i] + 1) return i; assert(false); return -1; } void remove_impossible(BS &alive, const int &opt, int res) { alive &= mask[res][opt]; } #define TESTING #ifdef TESTING void test_all() { map<int, int> cnt; // {# of queries, count} For(i, 0, 719) { For(j, 0, 5) W[j] = perm[i][j] + 1; _setNewTest(W); orderCoins(); cnt[_numQueries]++; } for(auto &i:cnt) cerr << i.F << ": " << i.S << "\n"; } #endif void init(int T) { #ifdef NYAOWO seed = clock(); cerr << "seed: " << seed << "\n"; #else seed = 13672; #endif assert(T < 20); int a[6] = {0, 1, 2, 3, 4, 5}; perm.clear(); do { perm.eb(a, a + 6); } while(next_permutation(a, a + 6)); For(i, 0, 5) For(j, i + 1, 5) For(k, j + 1, 5) { options.push_back({0, i, j, k}); options.push_back({1, i, j, k}); options.push_back({2, i, j, k}); For(l, 0, 5) { if(i == l || j == l || k == l) continue; options.push_back({3, i, j, k, l}); } } For(r, 1, 3) mask[r].clear(); for(auto &opt:options) For(r, 1, 3) { mask[r].eb(); mask[r].back().reset(); For(i, 0, 719) if(match(perm[i], opt, r)) mask[r].back()[i] = 1; } cerr << sz(perm) << "\n"; cerr << sz(options) << "\n"; #ifdef TESTING test_all(); #endif } void orderCoins() { rng.seed(seed); BS alive; For(i, 0, 719) alive[i] = 1; while(alive.count() > 1) { int k = best_opt(alive); int r = make_query(options[k]); remove_impossible(alive, k, r); // cout << sz(alive) << " " << k << " " << r << "\n" << flush; } int pos = -1; For(i, 0, 719) if(alive[i]) pos = i; vector<int> &ord = perm[pos]; For(i, 0, 5) W[ord[i]] = i + 1; #ifndef TESTING answer(W); #endif }

Compilation message (stderr)

scales.cpp: In function 'void test_all()':
scales.cpp:120:9: error: '_setNewTest' was not declared in this scope
  120 |         _setNewTest(W);
      |         ^~~~~~~~~~~
scales.cpp:122:13: error: '_numQueries' was not declared in this scope
  122 |         cnt[_numQueries]++;
      |             ^~~~~~~~~~~