답안 #706660

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
706660 2023-03-07T09:46:27 Z marvinthang 저울 (IOI15_scales) C++17
100 / 100
36 ms 592 KB
/*************************************
*    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); } 

#define Bitset bitset<720>

vector <vector <int>> ask, perms, pos;
int pw3[10];

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(int p, vector <int> v) {
    sort(1 + ALL(v), [&] (int a, int b) { return pos[p][a] < pos[p][b]; });
    if (v[0] < 1) return v[1 - v[0]];
    FOR(i, 1, 4) if (pos[p][v[i]] > pos[p][v[0]]) return v[i];
    return v[1];
}

struct Cmp {
    bool operator() (const Bitset &a, const Bitset &b) const {
        REP(i, 720) if (a[i] != b[i]) return a[i] < b[i];
        return false;
    }
};

map <Bitset, vector <int>, Cmp> cache[7];

bool check(Bitset bs, int turn) {
    int cnt = bs.count();
    if (cnt <= 1) return true;
    if (cache[turn].count(bs)) return !cache[turn][bs].empty();
    for (auto v: ask) {
        vector <int> id(7);
        REP(i, 3) id[v[i + 1]] = i;
        vector <Bitset> nxt(3);
        REP(i, 720) if (bs[i]) nxt[id[Ask(i, v)]][i] = 1;
        bool ok = true;
        for (Bitset &b: nxt) if (b.count() > pw3[turn - 1]) {
            ok = false;
            break;
        }
        if (!ok) continue;
        for (Bitset &b: nxt) if (!check(b, turn - 1)) {
            ok = false;
            break;
        }
        if (ok) {
            cache[turn][bs] = v;
            return true;
        }
    }
    cache[turn][bs] = vector<int>{};
    return false;
}

void init(int T) {
    pw3[0] = 1;
    REP(i, 6) pw3[i + 1] = pw3[i] * 3;
    vector <int> v {1, 2, 3, 4, 5, 6};
    do {
        perms.push_back(v);
        pos.push_back(vector<int>(7));
        REP(i, 6) pos.back()[perms.back()[i]] = i;
    } while (next_permutation(ALL(v)));
    FOR(a, 1, 7) FOR(b, a + 1, 7) FOR(c, b + 1, 7) {
        FOR(d, 1, 7) if (d != a && d != b && d != c) ask.push_back(vector<int>{d, a, b, c});
        for (int i: {1, 0, 2}) ask.push_back(vector<int>{-i, a, b, c});
    }
    Bitset bs;
    bs.set();
    check(bs, 6);
}

void orderCoins() {
    Bitset bs;
    bs.set();
    FORD(i, 7, 1) {
        vector <int> v = cache[i][bs];
        int cur = Ask(v);
        REP(i, 720) if (bs[i] && Ask(i, v) != cur) bs[i] = 0;
    }
    int W[6];
    copy(ALL(perms[bs._Find_first()]), W);
    answer(W);
}

Compilation message

scales.cpp: In function 'bool check(std::bitset<720>, int)':
scales.cpp:78:23: warning: conversion from 'std::size_t' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   78 |     int cnt = bs.count();
      |               ~~~~~~~~^~
scales.cpp:87:44: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   87 |         for (Bitset &b: nxt) if (b.count() > pw3[turn - 1]) {
      |                                  ~~~~~~~~~~^~~~~~~~~~~~~~~
scales.cpp: In function 'void init(int)':
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:114:18: note: in expansion of macro 'FOR'
  114 |     FOR(a, 1, 7) FOR(b, a + 1, 7) FOR(c, b + 1, 7) {
      |                  ^~~
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:114:5: note: in expansion of macro 'FOR'
  114 |     FOR(a, 1, 7) FOR(b, a + 1, 7) FOR(c, b + 1, 7) {
      |     ^~~
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:114:35: note: in expansion of macro 'FOR'
  114 |     FOR(a, 1, 7) FOR(b, a + 1, 7) FOR(c, b + 1, 7) {
      |                                   ^~~
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:114:18: note: in expansion of macro 'FOR'
  114 |     FOR(a, 1, 7) FOR(b, a + 1, 7) FOR(c, b + 1, 7) {
      |                  ^~~
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:115:9: note: in expansion of macro 'FOR'
  115 |         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:114:35: note: in expansion of macro 'FOR'
  114 |     FOR(a, 1, 7) FOR(b, a + 1, 7) FOR(c, b + 1, 7) {
      |                                   ^~~
scales.cpp:105:15: warning: unused parameter 'T' [-Wunused-parameter]
  105 | void init(int T) {
      |           ~~~~^
scales.cpp: In function 'void orderCoins()':
scales.cpp:129:13: warning: declaration of 'i' shadows a previous local [-Wshadow]
  129 |         REP(i, 720) if (bs[i] && Ask(i, v) != cur) bs[i] = 0;
      |             ^
scales.cpp:20:39: note: in definition of macro 'REP'
   20 | #define           REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
      |                                       ^
scales.cpp:126:10: note: shadowed declaration is here
  126 |     FORD(i, 7, 1) {
      |          ^
scales.cpp:23:39: note: in definition of macro 'FORD'
   23 | #define       FORD(i, b, a)  for (int i = (b), _a = (a); --i >= _a; )
      |                                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 444 KB Output is correct
2 Correct 27 ms 460 KB Output is correct
3 Correct 28 ms 428 KB Output is correct
4 Correct 28 ms 464 KB Output is correct
5 Correct 30 ms 460 KB Output is correct
6 Correct 27 ms 464 KB Output is correct
7 Correct 28 ms 444 KB Output is correct
8 Correct 27 ms 464 KB Output is correct
9 Correct 26 ms 460 KB Output is correct
10 Correct 27 ms 592 KB Output is correct
11 Correct 26 ms 444 KB Output is correct
12 Correct 27 ms 472 KB Output is correct
13 Correct 36 ms 452 KB Output is correct
14 Correct 34 ms 472 KB Output is correct
15 Correct 27 ms 416 KB Output is correct
16 Correct 27 ms 432 KB Output is correct
17 Correct 33 ms 460 KB Output is correct
18 Correct 27 ms 456 KB Output is correct
19 Correct 28 ms 424 KB Output is correct
20 Correct 28 ms 456 KB Output is correct
21 Correct 28 ms 468 KB Output is correct
22 Correct 27 ms 432 KB Output is correct
23 Correct 27 ms 436 KB Output is correct
24 Correct 27 ms 564 KB Output is correct
25 Correct 27 ms 456 KB Output is correct
26 Correct 27 ms 480 KB Output is correct
27 Correct 35 ms 440 KB Output is correct
28 Correct 36 ms 440 KB Output is correct
29 Correct 28 ms 460 KB Output is correct
30 Correct 27 ms 424 KB Output is correct
31 Correct 27 ms 448 KB Output is correct
32 Correct 28 ms 452 KB Output is correct
33 Correct 28 ms 448 KB Output is correct
34 Correct 29 ms 460 KB Output is correct
35 Correct 29 ms 468 KB Output is correct
36 Correct 27 ms 460 KB Output is correct
37 Correct 27 ms 436 KB Output is correct
38 Correct 27 ms 436 KB Output is correct
39 Correct 27 ms 468 KB Output is correct
40 Correct 27 ms 480 KB Output is correct