# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
787982 |
2023-07-19T15:46:29 Z |
ymm |
저울 (IOI15_scales) |
C++17 |
|
33 ms |
488 KB |
#include "scales.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef std::pair<int,int> pii;
typedef long long ll;
using namespace std;
typedef array<int, 6> perm;
int whichval(int, int b, int c, int x) {
return (b == x) + 2*(c == x);
}
tuple<int,int,int> srt(const perm &p, int a, int b, int c) {
if (p[a] > p[b]) swap(a, b);
if (p[b] > p[c]) swap(b, c);
if (p[a] > p[b]) swap(a, b);
return {a, b, c};
}
int mn(const perm &p, int a, int b, int c) {
auto [x, y, z] = srt(p, a, b, c);
return whichval(a, b, c, x);
}
int mx(const perm &p, int a, int b, int c) {
auto [x, y, z] = srt(p, a, b, c);
return whichval(a, b, c, z);
}
int med(const perm &p, int a, int b, int c) {
auto [x, y, z] = srt(p, a, b, c);
return whichval(a, b, c, y);
}
int nxt(const perm &p, int a, int b, int c, int d) {
auto [x, y, z] = srt(p, a, b, c);
if (p[d] < p[x]) return whichval(a, b, c, x);
if (p[d] < p[y]) return whichval(a, b, c, y);
if (p[d] < p[z]) return whichval(a, b, c, z);
return whichval(a, b, c, x);
}
vector<tuple<int,int,int>> sel3;
vector<tuple<int,int,int,int>> sel4;
vector<perm> perms;
int (*f2q(int (*f)(const perm &, int, int, int)))(int, int, int) {
if (f == mn) return getLightest;
if (f == mx) return getHeaviest;
if (f == med) return getMedian;
return NULL;
}
perm solve(const vector<perm> &ps)
{
if (ps.size() == 1)
return ps[0];
int mnch = INT_MAX;
array<vector<perm>, 3> chvec;
pair<void *, void *> ch;
for (auto &sel : sel4) {
auto [a, b, c, d] = sel;
array<vector<perm>, 3> vec;
for (const auto &p : ps)
vec[nxt(p, a, b, c, d)].push_back(p);
int x = max({vec[0].size(), vec[1].size(), vec[2].size()});
if (x < mnch) {
mnch = x;
chvec = vec;
ch = {(void *)getNextLightest, (void *)&sel};
}
}
for (auto f : {med, mn, mx}) {
for (auto &sel : sel3) {
auto [a, b, c] = sel;
array<vector<perm>, 3> vec;
for (const auto &p : ps)
vec[f(p, a, b, c)].push_back(p);
int x = max({vec[0].size(), vec[1].size(), vec[2].size()});
if (x < mnch) {
mnch = x;
chvec = vec;
ch = {(void *)f2q(f), (void *)&sel};
}
}
}
if (ch.first == getNextLightest) {
auto [a, b, c, d] = *(tuple<int,int,int,int> *)ch.second;
int x = getNextLightest(a+1, b+1, c+1, d+1)-1;
int i = whichval(a, b, c, x);
return solve(chvec[i]);
} else {
auto f = (int (*)(int, int, int))ch.first;
auto [a, b, c] = *(tuple<int,int,int> *)ch.second;
int x = f(a+1, b+1, c+1)-1;
int i = whichval(a, b, c, x);
return solve(chvec[i]);
}
}
void init(int T) {
Loop (i,0,6) Loop (j,i+1,6) Loop (k,j+1,6)
sel3.emplace_back(i, j, k);
Loop (d,0,6) {
Loop (i,0,6) Loop (j,i+1,6) Loop (k,j+1,6) {
if (i != d && j != d && k != d)
sel4.emplace_back(i, j, k, d);
}
}
perm p = {0, 1, 2, 3, 4, 5};
do
perms.push_back(p);
while (next_permutation(p.begin(), p.end()));
}
void orderCoins() {
auto ans = solve(perms);
int w[6];
Loop (i,0,6)
w[ans[i]] = i+1;
answer(w);
}
Compilation message
scales.cpp: In function 'perm solve(const std::vector<std::array<int, 6> >&)':
scales.cpp:65:14: warning: conversion from 'long unsigned int' to 'int' may change value [-Wconversion]
65 | int x = max({vec[0].size(), vec[1].size(), vec[2].size()});
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scales.cpp:78:15: warning: conversion from 'long unsigned int' to 'int' may change value [-Wconversion]
78 | int x = max({vec[0].size(), vec[1].size(), vec[2].size()});
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scales.cpp: In function 'void init(int)':
scales.cpp:100:15: warning: unused parameter 'T' [-Wunused-parameter]
100 | void init(int T) {
| ~~~~^
scales.cpp: In function 'void orderCoins()':
scales.cpp:119:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
119 | w[ans[i]] = i+1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
340 KB |
Output is correct |
2 |
Correct |
28 ms |
340 KB |
Output is correct |
3 |
Correct |
27 ms |
388 KB |
Output is correct |
4 |
Correct |
27 ms |
392 KB |
Output is correct |
5 |
Correct |
28 ms |
340 KB |
Output is correct |
6 |
Correct |
28 ms |
380 KB |
Output is correct |
7 |
Correct |
28 ms |
340 KB |
Output is correct |
8 |
Correct |
28 ms |
372 KB |
Output is correct |
9 |
Correct |
31 ms |
372 KB |
Output is correct |
10 |
Correct |
28 ms |
384 KB |
Output is correct |
11 |
Correct |
28 ms |
380 KB |
Output is correct |
12 |
Correct |
28 ms |
380 KB |
Output is correct |
13 |
Correct |
28 ms |
396 KB |
Output is correct |
14 |
Correct |
27 ms |
376 KB |
Output is correct |
15 |
Correct |
28 ms |
388 KB |
Output is correct |
16 |
Correct |
28 ms |
340 KB |
Output is correct |
17 |
Correct |
28 ms |
380 KB |
Output is correct |
18 |
Correct |
27 ms |
340 KB |
Output is correct |
19 |
Correct |
28 ms |
388 KB |
Output is correct |
20 |
Correct |
28 ms |
384 KB |
Output is correct |
21 |
Correct |
28 ms |
368 KB |
Output is correct |
22 |
Correct |
28 ms |
388 KB |
Output is correct |
23 |
Correct |
28 ms |
388 KB |
Output is correct |
24 |
Correct |
28 ms |
380 KB |
Output is correct |
25 |
Correct |
28 ms |
380 KB |
Output is correct |
26 |
Correct |
30 ms |
340 KB |
Output is correct |
27 |
Correct |
28 ms |
392 KB |
Output is correct |
28 |
Correct |
28 ms |
340 KB |
Output is correct |
29 |
Correct |
31 ms |
340 KB |
Output is correct |
30 |
Correct |
28 ms |
392 KB |
Output is correct |
31 |
Correct |
28 ms |
380 KB |
Output is correct |
32 |
Correct |
28 ms |
340 KB |
Output is correct |
33 |
Correct |
29 ms |
488 KB |
Output is correct |
34 |
Correct |
29 ms |
364 KB |
Output is correct |
35 |
Correct |
28 ms |
392 KB |
Output is correct |
36 |
Correct |
27 ms |
384 KB |
Output is correct |
37 |
Correct |
33 ms |
340 KB |
Output is correct |
38 |
Correct |
28 ms |
360 KB |
Output is correct |
39 |
Correct |
28 ms |
360 KB |
Output is correct |
40 |
Correct |
28 ms |
380 KB |
Output is correct |