Submission #706621

#TimeUsernameProblemLanguageResultExecution timeMemory
706621marvinthangScales (IOI15_scales)C++17
76.19 / 100
261 ms484 KiB
/************************************* * author: marvinthang * * created: 06.03.2023 15:25:06 * *************************************/ #include "scales.h" #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define left ___left #define right ___right #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #define MASK(i) (1LL << (i)) #define BIT(x, i) ((x) >> (i) & 1) #define __builtin_popcount __builtin_popcountll #define ALL(v) (v).begin(), (v).end() #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define REPD(i, n) for (int i = (n); i--; ) #define FOR(i, a, b) for (int i = (a), _b = (b); i < _b; ++i) #define FORD(i, b, a) for (int i = (b), _a = (a); --i >= _a; ) #define FORE(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORDE(i, b, a) for (int i = (b), _a = (a); i >= _a; --i) #define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u) #define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u) #ifdef LOCAL #include "debug.h" #else #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } #define DB(...) 23 #define db(...) 23 #define debug(...) 23 #endif template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; } template <class U, class V> scan_op(pair <U, V>) { return in >> u.fi >> u.se; } template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.first << ", " << u.second << ')'; } template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; } template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); } template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); } // end of template mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long rand(long long l, long long h) { return uniform_int_distribution <long long> (l, h) (rng); } void init(int T) { } int Ask(const vector <int> &v) { if (v[0] == -0) return getLightest(v[1], v[2], v[3]); if (v[0] == -1) return getMedian(v[1], v[2], v[3]); if (v[0] == -2) return getHeaviest(v[1], v[2], v[3]); return getNextLightest(v[1], v[2], v[3], v[0]); } int Ask(const vector <int> &p, vector <int> v) { vector <int> q(7); REP(i, 6) q[p[i]] = i; sort(1 + ALL(v), [&] (int a, int b) { return q[a] < q[b]; }); if (v[0] < 1) { if (v[0] == -0) return v[1]; if (v[0] == -1) return v[2]; return v[3]; } FOR(i, 1, 4) if (q[v[i]] > q[v[0]]) return v[i]; return v[1]; } void orderCoins() { vector <vector <int>> perms, ask; vector <int> v {1, 2, 3, 4, 5, 6}; do perms.push_back(v); while (next_permutation(ALL(v))); FOR(a, 3, 7) FOR(b, 1, a) FOR(c, 1, b) { REP(i, 3) ask.push_back(vector<int>{-i, a, b, c}); FOR(d, 1, 7) if (d != a && d != b && d != c) ask.push_back(vector<int>{d, a, b, c}); } while (perms.size() > 1) { vector <vector <int>> nxt; vector <int> ma{ (int) perms.size() + 1, 0, 0}; for (auto v: ask) { vector <int> cnt(7); for (auto p: perms) ++cnt[Ask(p, v)]; vector <int> cur {cnt[v[1]], cnt[v[2]], cnt[v[3]]}; sort(cur.rbegin(), cur.rend()); if (cur[0] < ma[0] || (cur[0] == ma[0] && cur[1] < ma[1])) { nxt.clear(); nxt.push_back(v); ma = cur; } else if (cur[0] == ma[0] && cur[1] == ma[1]) nxt.push_back(v); } vector <int> v(nxt[rand(0, (int) nxt.size() - 1)]); int x = Ask(v); nxt.clear(); for (auto p: perms) if (Ask(p, v) == x) nxt.push_back(p); perms = move(nxt); } int W[6]; copy(ALL(perms[0]), W); answer(W); }

Compilation message (stderr)

scales.cpp: In function 'void init(int)':
scales.cpp:49:15: warning: unused parameter 'T' [-Wunused-parameter]
   49 | void init(int T) {
      |           ~~~~^
scales.cpp: In function 'void orderCoins()':
scales.cpp:22:48: warning: declaration of '_b' shadows a previous local [-Wshadow]
   22 | #define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i)
      |                                                ^~
scales.cpp:78:18: note: in expansion of macro 'FOR'
   78 |     FOR(a, 3, 7) FOR(b, 1, a) FOR(c, 1, b) {
      |                  ^~~
scales.cpp:22:48: note: shadowed declaration is here
   22 | #define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i)
      |                                                ^~
scales.cpp:78:5: note: in expansion of macro 'FOR'
   78 |     FOR(a, 3, 7) FOR(b, 1, a) FOR(c, 1, b) {
      |     ^~~
scales.cpp:22:48: warning: declaration of '_b' shadows a previous local [-Wshadow]
   22 | #define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i)
      |                                                ^~
scales.cpp:78:31: note: in expansion of macro 'FOR'
   78 |     FOR(a, 3, 7) FOR(b, 1, a) FOR(c, 1, b) {
      |                               ^~~
scales.cpp:22:48: note: shadowed declaration is here
   22 | #define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i)
      |                                                ^~
scales.cpp:78:18: note: in expansion of macro 'FOR'
   78 |     FOR(a, 3, 7) FOR(b, 1, a) FOR(c, 1, b) {
      |                  ^~~
scales.cpp:22:48: warning: declaration of '_b' shadows a previous local [-Wshadow]
   22 | #define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i)
      |                                                ^~
scales.cpp:80:9: note: in expansion of macro 'FOR'
   80 |         FOR(d, 1, 7) if (d != a && d != b && d != c) ask.push_back(vector<int>{d, a, b, c});
      |         ^~~
scales.cpp:22:48: note: shadowed declaration is here
   22 | #define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i)
      |                                                ^~
scales.cpp:78:31: note: in expansion of macro 'FOR'
   78 |     FOR(a, 3, 7) FOR(b, 1, a) FOR(c, 1, b) {
      |                               ^~~
scales.cpp:85:19: warning: declaration of 'v' shadows a previous local [-Wshadow]
   85 |         for (auto v: ask) {
      |                   ^
scales.cpp:75:18: note: shadowed declaration is here
   75 |     vector <int> v {1, 2, 3, 4, 5, 6};
      |                  ^
scales.cpp:96:22: warning: declaration of 'v' shadows a previous local [-Wshadow]
   96 |         vector <int> v(nxt[rand(0, (int) nxt.size() - 1)]);
      |                      ^
scales.cpp:75:18: note: shadowed declaration is here
   75 |     vector <int> v {1, 2, 3, 4, 5, 6};
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...