# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1058186 | thieunguyenhuy | 저울 (IOI15_scales) | C++17 | 16 ms | 9308 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#ifndef hwe
#include "scales.h"
#endif
#include <bits/stdc++.h>
using namespace std;
#define popcount(n) (__builtin_popcountll((n)))
#define clz(n) (__builtin_clzll((n)))
#define ctz(n) (__builtin_ctzll((n)))
#define lg(n) (63 - __builtin_clzll((n)))
#define BIT(n, i) (((n) >> (i)) & 1ll)
#define MASK(i) (1ll << (i))
#define FLIP(n, i) ((n) ^ (1ll << (i)))
#define ON(n, i) ((n) | MASK(i))
#define OFF(n, i) ((n) & ~MASK(i))
#define Int __int128
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long, long long>> vll;
typedef vector<pair<long long, int>> vli;
typedef vector<pair<int, long long>> vil;
template <class T1, class T2>
bool maximize(T1 &x, T2 y) {
if (x < y) {
x = y;
return true;
}
return false;
}
template <class T1, class T2>
bool minimize(T1 &x, T2 y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <class T>
void remove_duplicate(vector<T> &ve) {
sort (ve.begin(), ve.end());
ve.resize(unique(ve.begin(), ve.end()) - ve.begin());
}
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
template <class T> T random(T l, T r) {
return uniform_int_distribution<T>(l, r)(rng);
}
template <class T> T random(T r) {
return rng() % r;
}
const int N = 100000 + 5;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
int pw[] = {1, 3, 9, 27, 81, 243, 729};
int W[6];
#ifdef hwe
void answer(int W[]) {
for (int i = 0; i < 6; ++i) cerr << W[i] << ' ';
cerr << '\n';
}
int getLightest(int a, int b, int c);
int getMedian(int a, int b, int );
int getHeaviest(int a, int b, int c);
#endif
int numNode;
int ope[N];
pii child[N][3];
vector<int> candidates[N];
vector<int> to_vec(int num) {
vector<int> ret;
while (num > 0) ret.emplace_back(num % 10), num /= 10;
reverse(ret.begin(), ret.end());
return ret;
}
int to_num(vector<int> ve) {
int num = 0;
for (auto x : ve) num = num * 10 + x;
return num;
}
void gen_tree(int node, int depth) {
if (candidates[node].size() <= 1) return;
if (depth == 0) return;
vector<tuple<int, int, int>> triples;
for (int i = 1; i <= 4; ++i) for (int j = i + 1; j <= 5; ++j) for (int k = j + 1; k <= 6; ++k)
triples.emplace_back(i, j, k);
shuffle(triples.begin(), triples.end(), rng);
for (auto it : triples) {
int x = get<0>(it), y = get<1>(it), z = get<2>(it);
for (int operation : {0, 1, 2}) {
int cnt[3]; cnt[0] = cnt[1] = cnt[2] = 0;
for (auto candidate : candidates[node]) {
vector<int> ve = to_vec(candidate); pii p[3];
for (int i = 0; i < ve.size(); ++i) {
if (ve[i] == x) p[0] = make_pair(i, 0);
if (ve[i] == y) p[1] = make_pair(i, 1);
if (ve[i] == z) p[2] = make_pair(i, 2);
}
sort (p, p + 3);
++cnt[p[operation].se];
}
if (max({cnt[0], cnt[1], cnt[2]}) > pw[depth - 1]) continue;
ope[node] = operation;
child[node][0] = make_pair(++numNode, x);
child[node][1] = make_pair(++numNode, y);
child[node][2] = make_pair(++numNode, z);
for (auto candidate : candidates[node]) {
vector<int> ve = to_vec(candidate); pii p[3];
for (int i = 0; i < ve.size(); ++i) {
if (ve[i] == x) p[0] = make_pair(i, 0);
if (ve[i] == y) p[1] = make_pair(i, 1);
if (ve[i] == z) p[2] = make_pair(i, 2);
}
sort (p, p + 3);
candidates[child[node][p[operation].se].fi].emplace_back(candidate);
}
gen_tree(child[node][0].fi, depth - 1);
gen_tree(child[node][1].fi, depth - 1);
gen_tree(child[node][2].fi, depth - 1);
return;
}
}
}
void init(int t) {
vector<int> p = {1, 2, 3, 4, 5, 6};
numNode = 0;
do {
candidates[0].emplace_back(to_num(p));
} while (next_permutation(p.begin(), p.end()));
gen_tree(0, 6);
}
void orderCoins() {
int current_node = 0;
auto play = [&]() {
int tmp, x = child[current_node][0].se, y = child[current_node][1].se, z = child[current_node][2].se;
if (ope[current_node] == 0) tmp = getLightest(x, y, z);
else if (ope[current_node] == 1) tmp = getMedian(x, y, z);
else tmp = getHeaviest(x, y, z);
if (tmp == x) return 0;
if (tmp == y) return 1;
return 2;
};
while (true) {
if (candidates[current_node].size() == 1) {
vector<int> ve = to_vec(candidates[current_node][0]);
for (int i = 0; i < 6; ++i) W[i] = ve[i];
answer(W);
}
int tmp = play(); current_node = child[current_node][tmp].fi;
}
}
#ifdef hwe
signed main() {
cerr << '\n'; return 0;
}
#endif
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |