제출 #787982

#제출 시각아이디문제언어결과실행 시간메모리
787982ymm저울 (IOI15_scales)C++17
100 / 100
33 ms488 KiB
#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); }

컴파일 시 표준 에러 (stderr) 메시지

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;
      |               ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...