# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
122631 | win11905 | 저울 (IOI15_scales) | C++11 | 8 ms | 504 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "scales.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
vector<pair<int, vector<int> > > que;
vector<vector<int> > perm;
int ids[] = {0, 1, 1, 1, 5, 4, -1, 5, 4, -1, 3, 3, -1, 16, 16, 86, 29, 40, -1, -1, -1, -1, 16, 16, 86, 32, 40, -1, -1, -1, -1, 30, 39, -1, 33, 39, -1, -1, -1, -1, 24, 29, -1, 96, 0, -1, 7, 41, 24, 107, 86, 3, 107, 96, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 96, 0, -1, 21, 29, -1, 6, 41, 24, 107, 89, 3, 107, 96, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 107, 86, 4, 107, 96, 6, -1, -1, -1, 107, 89, 4, 107, 96, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 52, 52, 52, 50, 50, -1, -1, -1, -1, 55, 24, 34, 52, -1, -1, -1, -1, -1, 89, 89, 65, 58, 58, 7, 58, 31, 41, 65, 34, 24, 65, 18, 21, 52, 50, -1, 75, 34, 18, 75, 24, 18, 55, 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 58, 21, 31, 52, -1, -1, -1, -1, -1, 52, 52, 52, 50, 50, -1, -1, -1, -1, 89, 89, 68, 58, 58, 6, 58, 31, 41, 68, 31, 21, 68, 18, 21, 52, 50, -1, 75, 31, 18, 75, 21, 18, 55, 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 65, 34, 24, 65, 18, 21, 52, 51, -1, 75, 34, 18, 75, 24, 18, 55, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 68, 31, 21, 68, 18, 21, 52, 51, -1, 75, 31, 18, 75, 21, 18, 55, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 63, 85, 54, 63, -1, 96, 63, -1, 96, 58, 107, -1, 58, 107, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 34, 68, 34, 107, 50, 68, 20, 68, 51, 84, 64, 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 16, 41, 75, 16, 41, 75, 30, 107, 107, 24, 16, 75, 24, 65, 7, 58, 68, 30, 7, 75, 75, 7, 64, 7, 75, 75, 54, 24, 58, 24, 96, 50, 58, 30, 58, 51, 58, 24, 24, 63, 96, 58, -1, 58, 89, 84, 54, 64, 58, 107, -1, -1, -1, -1, 18, 52, 18, 86, 54, 52, 52, 30, 51, 52, 18, 18, 86, 64, 52, 52, 20, 51, -1, 85, 68, 52, 107, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 31, 65, 31, 107, 50, 65, 19, 65, 51, 64, 84, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 85, 63, 53, -1, 63, 96, -1, 63, 96, 55, 107, -1, 55, 107, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 16, 41, 75, 16, 41, 75, 29, 107, 107, 24, 17, 75, 24, 65, 6, 58, 68, 29, 6, 75, 75, 6, 63, 6, 75, 75, 53, 21, 55, 21, 96, 50, 55, 29, 55, 51, 55, 21, 21, 96, 63, 55, 16, 55, 51, 54, 84, 63, 55, 107, -1, -1, -1, -1, 18, 52, 18, 89, 54, 52, 30, 52, 51, 52, 18, 18, 89, 64, 52, 20, 52, 51, 50, 85, 64, 52, 107, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 58, 24, 96, 51, 58, 29, 58, 50, 58, 24, 24, 64, 96, 58, -1, 58, 89, 85, 53, 63, 58, 107, -1, -1, -1, -1, 18, 52, 18, 86, 53, 52, 52, 29, 50, 52, 18, 18, 86, 63, 52, 52, 19, 50, -1, 84, 68, 52, 107, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 21, 55, 21, 96, 51, 55, 30, 55, 50, 55, 21, 21, 96, 64, 55, 17, 55, 50, 53, 85, 64, 55, 107, -1, -1, -1, -1, 18, 52, 18, 89, 53, 52, 29, 52, 50, 52, 18, 18, 89, 63, 52, 19, 52, 50, 51, 84, 63, 52, 107, 0};
int mx = 0;
int zzz;
int dfs(int u, vector<int> vec, int lv) {
cerr << u << " -> " << vec.size() << endl;
if(vec.size() == 1) return vec[0];
mx = max(mx, u);
for(int ii = ids[u];;) {
auto& z = que[ii];
vector<int> Mp[6];
int abc;
if(z.x == 0) abc = getHeaviest(z.y[0]+1, z.y[1]+1, z.y[2]+1);
if(z.x == 1) abc = getLightest(z.y[0]+1, z.y[1]+1, z.y[2]+1);
if(z.x == 2) abc = getMedian(z.y[0]+1, z.y[1]+1, z.y[2]+1);
if(z.x == 3) abc = getNextLightest(z.y[0]+1, z.y[1]+1, z.y[2]+1, z.y[3]+1);
for(int v : vec) {
vector<pii> val;
for(int i = 0; i < 3; ++i) val.emplace_back(perm[v][z.y[i]], z.y[i]);
sort(val.begin(), val.end());
if(z.x == 0)
Mp[val[2].y].emplace_back(v);
else if(z.x == 1)
Mp[val[0].y].emplace_back(v);
else if(z.x == 2)
Mp[val[1].y].emplace_back(v);
else for(int i = 2; i >= -1; --i) {
if(i == -1) Mp[val[0].y].emplace_back(v);
else if(val[i].x > perm[v][z.y[3]]) Mp[val[i].y].emplace_back(v);
}
}
int step = 0;
for(int i = 0; i < 6; ++i) if(Mp[i].size()) {
step++;
if(i == abc-1)
return dfs(u*3 + step, Mp[i], lv / 3);
}
}
return false;
}
int nth = 6;
void init(int T) {
for(int i = 0; i < (1 << nth); ++i) {
vector<int> vec;
for(int j = 0; j < nth; ++j) if(i >> j & 1)
vec.emplace_back(j);
if(vec.size() == 3)
for(int j = 0; j < 3; ++j) que.emplace_back(j, vec);
if(vec.size() == 4) {
for(int i = 0; i < 4; ++i) {
vector<int> ret;
for(int j = 0; j < 4; ++j) if(i != j) ret.emplace_back(vec[j]);
ret.emplace_back(vec[i]);
que.emplace_back(3, ret);
}
}
}
vector<int> now;
for(int i = 0; i < nth; ++i) now.emplace_back(i+1);
do {
perm.emplace_back(now);
} while(next_permutation(now.begin(), now.end()));
}
void orderCoins() {
int* ans = new int[6];
vector<int> zz;
for(int i = 0; i < perm.size(); ++i) zz.emplace_back(i);
int k = dfs(0, zz, 2187);
cerr << "=> " << k << endl;
for(int i = 0; i < 6; ++i) ans[perm[k][i]-1] = i+1;
answer(ans);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |