답안 #584839

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584839 2022-06-28T04:45:58 Z hibiki 저울 (IOI15_scales) C++11
100 / 100
84 ms 404 KB
#include "scales.h"
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
 
struct query
{
    int a,b,c,d,type;
    query() {};
    query(int a, int b, int c, int d, int type): a(a), b(b), c(c), d(d), type(type) {};
};
 
vector<vector<int> > all;
vector<query> ask;
 
int fi_median(int a,int b,int c)
{
    if(max({a, b, c}) != a && min({a, b, c}) != a) return a;
    if(max({a, b, c}) != b && min({a, b, c}) != b) return b;
    if(max({a, b, c}) != c && min({a, b, c}) != c) return c;
    exit(-1);
    return -1;
}
 
int fi_next_light(int a,int b,int c,int d)
{
    int ret = 1e9;
    if(a > d)
        ret = min(ret, a);
    if(b > d)
        ret = min(ret, b);
    if(c > d)
        ret = min(ret, c);
    if(ret == 1e9)
        ret = min({a, b, c});
    return ret;
}
 
void init(int T) {
    vector<int> v;
    for(int i = 0; i < 6; i++) v.pb(i);
    do {
        all.pb(v);
    } while(next_permutation(all(v)));
  	for(int a = 0; a < 6; a++)
          for(int b = a + 1; b < 6; b++)
              for(int c = b + 1; c < 6; c++)
              {
                  ask.pb(query(a, b, c, 0, 0));
                  ask.pb(query(a, b, c, 0, 1));
                  ask.pb(query(a, b, c, 0, 2));
              }
  	for(int d = 0; d < 6; d++)
      for(int a = 0; a < 6; a++)
          for(int b = a + 1; b < 6; b++)
              for(int c = b + 1; c < 6; c++)
              {
                  if(a == d || b == d || c == d) continue;
                      ask.pb({a, b, c, d, 3});
              }
}
 
void orderCoins() {
    vector<vector<int> > pos = all;
    while(1)
    {
        if(sz(pos) == 1)
        {
            int ans[6];
            for(int i = 0; i < 6; i++)
                ans[(*pos.begin())[i]] = i + 1;
         	answer(ans);
            return ;
        }
 
        query best;
        int val = 1e9;
        for(auto cask: ask)
        {
            if(cask.type == 0)
            {
                int ta = 0, tb = 0, tc = 0;
                for(auto nw: pos)
                {
                    if(max({nw[cask.a], nw[cask.b], nw[cask.c]}) == nw[cask.a]) ta++;
                    if(max({nw[cask.a], nw[cask.b], nw[cask.c]}) == nw[cask.b]) tb++;
                    if(max({nw[cask.a], nw[cask.b], nw[cask.c]}) == nw[cask.c]) tc++;
                }
                int mx = max({ta, tb, tc});
                if(mx <= val)
                    val = mx, best = cask;
            }
            else if(cask.type == 1)
            {
                int ta = 0, tb = 0, tc = 0;
                for(auto nw: pos)
                {
                    if(min({nw[cask.a], nw[cask.b], nw[cask.c]}) == nw[cask.a]) ta++;
                    if(min({nw[cask.a], nw[cask.b], nw[cask.c]}) == nw[cask.b]) tb++;
                    if(min({nw[cask.a], nw[cask.b], nw[cask.c]}) == nw[cask.c]) tc++;
                }
                int mx = max({ta, tb, tc});
                if(mx <= val)
                    val = mx, best = cask;
            }
            else if(cask.type == 2)
            {
                int ta = 0, tb = 0, tc = 0;
                for(auto nw: pos)
                {
                    if(fi_median(nw[cask.a], nw[cask.b], nw[cask.c]) == nw[cask.a]) ta++;
                    if(fi_median(nw[cask.a], nw[cask.b], nw[cask.c]) == nw[cask.b]) tb++;
                    if(fi_median(nw[cask.a], nw[cask.b], nw[cask.c]) == nw[cask.c]) tc++;
                }
                int mx = max({ta, tb, tc});
                if(mx <= val)
                    val = mx, best = cask;
            }
            else
            {
                int ta = 0, tb = 0, tc = 0;
                for(auto nw: pos)
                {
                    if(fi_next_light(nw[cask.a], nw[cask.b], nw[cask.c], nw[cask.d]) == nw[cask.a]) ta++;
                    if(fi_next_light(nw[cask.a], nw[cask.b], nw[cask.c], nw[cask.d]) == nw[cask.b]) tb++;
                    if(fi_next_light(nw[cask.a], nw[cask.b], nw[cask.c], nw[cask.d]) == nw[cask.c]) tc++;
                }
                int mx = max({ta, tb, tc});
                if(mx <= val)
                    val = mx, best = cask;
            }
        }
 
        vector<vector<int> > next;
        if(best.type == 0)
        {
            int ret = getHeaviest(best.a + 1, best.b + 1, best.c + 1) - 1;
            for(auto nw: pos)
            {
                if(max({nw[best.a], nw[best.b], nw[best.c]}) == nw[ret]) next.pb(nw);
            }
        }
        else if(best.type == 1)
        {
            int ret = getLightest(best.a + 1, best.b + 1, best.c + 1) - 1;
            for(auto nw: pos)
            {
                if(min({nw[best.a], nw[best.b], nw[best.c]}) == nw[ret]) next.pb(nw);
            }
        }
        else if(best.type == 2)
        {
            int ret = getMedian(best.a + 1, best.b + 1, best.c + 1) - 1;
            for(auto nw: pos)
            {
                if(fi_median(nw[best.a], nw[best.b], nw[best.c]) == nw[ret]) next.pb(nw);
            }
        }
        else
        {
            int ret = getNextLightest(best.a + 1, best.b + 1, best.c + 1, best.d + 1) - 1;
            for(auto nw: pos)
            {
                if(fi_next_light(nw[best.a], nw[best.b], nw[best.c], nw[best.d]) == nw[ret]) next.pb(nw);
            }
        }
        swap(pos, next);
    }
}

Compilation message

scales.cpp: In constructor 'query::query(int, int, int, int, int)':
scales.cpp:15:43: warning: declaration of 'type' shadows a member of 'query' [-Wshadow]
   15 |     query(int a, int b, int c, int d, int type): a(a), b(b), c(c), d(d), type(type) {};
      |                                       ~~~~^~~~
scales.cpp:13:17: note: shadowed declaration is here
   13 |     int a,b,c,d,type;
      |                 ^~~~
scales.cpp:15:36: warning: declaration of 'd' shadows a member of 'query' [-Wshadow]
   15 |     query(int a, int b, int c, int d, int type): a(a), b(b), c(c), d(d), type(type) {};
      |                                ~~~~^
scales.cpp:13:15: note: shadowed declaration is here
   13 |     int a,b,c,d,type;
      |               ^
scales.cpp:15:29: warning: declaration of 'c' shadows a member of 'query' [-Wshadow]
   15 |     query(int a, int b, int c, int d, int type): a(a), b(b), c(c), d(d), type(type) {};
      |                         ~~~~^
scales.cpp:13:13: note: shadowed declaration is here
   13 |     int a,b,c,d,type;
      |             ^
scales.cpp:15:22: warning: declaration of 'b' shadows a member of 'query' [-Wshadow]
   15 |     query(int a, int b, int c, int d, int type): a(a), b(b), c(c), d(d), type(type) {};
      |                  ~~~~^
scales.cpp:13:11: note: shadowed declaration is here
   13 |     int a,b,c,d,type;
      |           ^
scales.cpp:15:15: warning: declaration of 'a' shadows a member of 'query' [-Wshadow]
   15 |     query(int a, int b, int c, int d, int type): a(a), b(b), c(c), d(d), type(type) {};
      |           ~~~~^
scales.cpp:13:9: note: shadowed declaration is here
   13 |     int a,b,c,d,type;
      |         ^
scales.cpp: In constructor 'query::query(int, int, int, int, int)':
scales.cpp:15:43: warning: declaration of 'type' shadows a member of 'query' [-Wshadow]
   15 |     query(int a, int b, int c, int d, int type): a(a), b(b), c(c), d(d), type(type) {};
      |                                       ~~~~^~~~
scales.cpp:13:17: note: shadowed declaration is here
   13 |     int a,b,c,d,type;
      |                 ^~~~
scales.cpp:15:36: warning: declaration of 'd' shadows a member of 'query' [-Wshadow]
   15 |     query(int a, int b, int c, int d, int type): a(a), b(b), c(c), d(d), type(type) {};
      |                                ~~~~^
scales.cpp:13:15: note: shadowed declaration is here
   13 |     int a,b,c,d,type;
      |               ^
scales.cpp:15:29: warning: declaration of 'c' shadows a member of 'query' [-Wshadow]
   15 |     query(int a, int b, int c, int d, int type): a(a), b(b), c(c), d(d), type(type) {};
      |                         ~~~~^
scales.cpp:13:13: note: shadowed declaration is here
   13 |     int a,b,c,d,type;
      |             ^
scales.cpp:15:22: warning: declaration of 'b' shadows a member of 'query' [-Wshadow]
   15 |     query(int a, int b, int c, int d, int type): a(a), b(b), c(c), d(d), type(type) {};
      |                  ~~~~^
scales.cpp:13:11: note: shadowed declaration is here
   13 |     int a,b,c,d,type;
      |           ^
scales.cpp:15:15: warning: declaration of 'a' shadows a member of 'query' [-Wshadow]
   15 |     query(int a, int b, int c, int d, int type): a(a), b(b), c(c), d(d), type(type) {};
      |           ~~~~^
scales.cpp:13:9: note: shadowed declaration is here
   13 |     int a,b,c,d,type;
      |         ^
scales.cpp: In constructor 'query::query(int, int, int, int, int)':
scales.cpp:15:43: warning: declaration of 'type' shadows a member of 'query' [-Wshadow]
   15 |     query(int a, int b, int c, int d, int type): a(a), b(b), c(c), d(d), type(type) {};
      |                                       ~~~~^~~~
scales.cpp:13:17: note: shadowed declaration is here
   13 |     int a,b,c,d,type;
      |                 ^~~~
scales.cpp:15:36: warning: declaration of 'd' shadows a member of 'query' [-Wshadow]
   15 |     query(int a, int b, int c, int d, int type): a(a), b(b), c(c), d(d), type(type) {};
      |                                ~~~~^
scales.cpp:13:15: note: shadowed declaration is here
   13 |     int a,b,c,d,type;
      |               ^
scales.cpp:15:29: warning: declaration of 'c' shadows a member of 'query' [-Wshadow]
   15 |     query(int a, int b, int c, int d, int type): a(a), b(b), c(c), d(d), type(type) {};
      |                         ~~~~^
scales.cpp:13:13: note: shadowed declaration is here
   13 |     int a,b,c,d,type;
      |             ^
scales.cpp:15:22: warning: declaration of 'b' shadows a member of 'query' [-Wshadow]
   15 |     query(int a, int b, int c, int d, int type): a(a), b(b), c(c), d(d), type(type) {};
      |                  ~~~~^
scales.cpp:13:11: note: shadowed declaration is here
   13 |     int a,b,c,d,type;
      |           ^
scales.cpp:15:15: warning: declaration of 'a' shadows a member of 'query' [-Wshadow]
   15 |     query(int a, int b, int c, int d, int type): a(a), b(b), c(c), d(d), type(type) {};
      |           ~~~~^
scales.cpp:13:9: note: shadowed declaration is here
   13 |     int a,b,c,d,type;
      |         ^
scales.cpp: In function 'void init(int)':
scales.cpp:44:15: warning: unused parameter 'T' [-Wunused-parameter]
   44 | void init(int T) {
      |           ~~~~^
scales.cpp: In function 'void orderCoins()':
scales.cpp:75:13: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   75 |             for(int i = 0; i < 6; i++)
      |             ^~~
scales.cpp:77:11: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   77 |           answer(ans);
      |           ^~~~~~
scales.cpp:142:34: warning: 'best.query::a' may be used uninitialized in this function [-Wmaybe-uninitialized]
  142 |             int ret = getHeaviest(best.a + 1, best.b + 1, best.c + 1) - 1;
      |                       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scales.cpp:142:34: warning: 'best.query::b' may be used uninitialized in this function [-Wmaybe-uninitialized]
scales.cpp:142:34: warning: 'best.query::c' may be used uninitialized in this function [-Wmaybe-uninitialized]
scales.cpp:169:79: warning: 'best.query::d' may be used uninitialized in this function [-Wmaybe-uninitialized]
  169 |                 if(fi_next_light(nw[best.a], nw[best.b], nw[best.c], nw[best.d]) == nw[ret]) next.pb(nw);
      |                                                                               ^
scales.cpp:156:14: warning: 'best.query::type' may be used uninitialized in this function [-Wmaybe-uninitialized]
  156 |         else if(best.type == 2)
      |              ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 384 KB Output is correct
2 Correct 82 ms 392 KB Output is correct
3 Correct 74 ms 388 KB Output is correct
4 Correct 70 ms 340 KB Output is correct
5 Correct 72 ms 396 KB Output is correct
6 Correct 70 ms 380 KB Output is correct
7 Correct 69 ms 400 KB Output is correct
8 Correct 69 ms 340 KB Output is correct
9 Correct 68 ms 392 KB Output is correct
10 Correct 74 ms 340 KB Output is correct
11 Correct 72 ms 340 KB Output is correct
12 Correct 80 ms 340 KB Output is correct
13 Correct 66 ms 380 KB Output is correct
14 Correct 68 ms 340 KB Output is correct
15 Correct 68 ms 380 KB Output is correct
16 Correct 72 ms 384 KB Output is correct
17 Correct 77 ms 340 KB Output is correct
18 Correct 67 ms 404 KB Output is correct
19 Correct 69 ms 384 KB Output is correct
20 Correct 80 ms 400 KB Output is correct
21 Correct 69 ms 384 KB Output is correct
22 Correct 71 ms 380 KB Output is correct
23 Correct 66 ms 340 KB Output is correct
24 Correct 69 ms 400 KB Output is correct
25 Correct 67 ms 380 KB Output is correct
26 Correct 77 ms 400 KB Output is correct
27 Correct 73 ms 340 KB Output is correct
28 Correct 70 ms 340 KB Output is correct
29 Correct 69 ms 340 KB Output is correct
30 Correct 69 ms 384 KB Output is correct
31 Correct 84 ms 340 KB Output is correct
32 Correct 75 ms 388 KB Output is correct
33 Correct 78 ms 400 KB Output is correct
34 Correct 67 ms 340 KB Output is correct
35 Correct 69 ms 392 KB Output is correct
36 Correct 81 ms 340 KB Output is correct
37 Correct 82 ms 384 KB Output is correct
38 Correct 77 ms 384 KB Output is correct
39 Correct 68 ms 340 KB Output is correct
40 Correct 66 ms 400 KB Output is correct