Submission #917601

# Submission time Handle Problem Language Result Execution time Memory
917601 2024-01-28T13:12:01 Z nguyentunglam Scales (IOI15_scales) C++17
0 / 100
1000 ms 348 KB
#include "scales.h"
#include<bits/stdc++.h>
using namespace std;

mt19937 rng(1);

int n = 6;

int order[10];

vector<tuple<int, int, int> > three;
vector<tuple<int, int, int, int> > four;

void init(int T) {
  for(int a = 1; a <= n; a++) for(int b = a + 1; b <= n; b++) for(int c = b + 1; c <= n; c++) {
    three.emplace_back(a, b, c);
  }
  for(int d = 1; d <= n; d++) for(int a = 1; a <= n; a++) for(int b = a + 1; b <= n; b++) for(int c = b + 1; c <= n; c++) {
    if (d != a && d != b && d != c) {
      four.emplace_back(a, b, c, d);
    }
  }
}

int ask_three(int a, int b, int c, int type, vector<int> tmp) {
  order[1] = a; order[2] = b; order[3] = c;
  sort(order + 1, order + 4, [&] (const int &x, const int &y) {
       return tmp[x] < tmp[y];
       });
  return order[type];
}

int ask_four(int a, int b, int c, int d, vector<int> tmp) {
  int ret = 0;
  tmp[0] = 1e9;
  if (tmp[a] > tmp[d] && tmp[a] < tmp[ret]) ret = a;
  if (tmp[b] > tmp[d] && tmp[b] < tmp[ret]) ret = b;
  if (tmp[c] > tmp[d] && tmp[c] < tmp[ret]) ret = c;
  if (ret == 0) return ask_three(a, b, c, 1, tmp);
  return ret;
}

void orderCoins() {
//  shuffle(three.begin(), three.end(), rng);
//  shuffle(four.begin(), four.end(), rng);
  vector<vector<int> > p;

  for(int i = 1; i <= n; i++) order[i] = i;

  do {
    vector<int> tmp(n + 1);
    for(int i = 1; i <= n; i++) tmp[i] = order[i];
    p.push_back(tmp);
  } while (next_permutation(order + 1, order + n + 1));

  while (p.size() > 1) {
    int best = 1e9;
    int _a, _b, _c, _d, _t;

    for(auto &[a, b, c, d] : four) {
      int worst = 0;
      for(int result = 1; result <= n; result++) {
        int sat = 0;
        for(auto &tmp : p) sat += result == ask_four(a, b, c, d, tmp);
        if (sat) worst = max(worst, sat);
      }
      if (!worst) continue;
      if (best > worst) {
        best = worst;
        _a = a;
        _b = b;
        _c = c;
        _d = d;
        _t = 0;
      }
    }

    for(auto &[a, b, c] : three) for(int type = 3; type >= 1; type++) {
      int worst = 0;
      for(int result = 1; result <= n; result++) {
        int sat = 0;
        for(auto &tmp : p) sat += result == ask_three(a, b, c, type, tmp);
        if (sat) worst = max(worst, sat);
      }
      if (!worst) continue;
      if (best > worst) {
        best = worst;
        _a = a;
        _b = b;
        _c = c;
        _t = type;
      }
    }

//    if (best == p.size()) break;
    assert(best < p.size());

    #ifdef ngu
    cout << _a << " " << _b << " " << _c << " " << _d << " " << _t << endl;
    #endif // ngu

    int result = 0;
    vector<vector<int> > _p;
    if (_t) {
      if (_t == 1) result = getLightest(_a, _b, _c);
      if (_t == 2) result = getMedian(_a, _b, _c);
      if (_t == 3) result = getHeaviest(_a, _b, _c);
      for(auto &tmp : p) if (ask_three(_a, _b, _c, _t, tmp) == result) {
        _p.push_back(tmp);
      }
      assert(_p.size() < p.size());
      p = _p;
    }

    else {
      result = getNextLightest(_a, _b, _c, _d);
      for(auto &tmp : p) if (ask_four(_a, _b, _c, _d, tmp) == result) {
        _p.push_back(tmp);
      }
      assert(_p.size() < p.size());
      p = _p;
    }
  }

  vector<int> tmp = p.back();
  int hidden[n];
  for(int i = 1; i <= n; i++) hidden[tmp[i] - 1] = i;
  #ifdef ngu
  for(int i = 0; i < n; i++) cerr << hidden[i] << " ";
  #endif // ngu

  answer(hidden);
}

Compilation message

scales.cpp: In function 'void init(int)':
scales.cpp:14:15: warning: unused parameter 'T' [-Wunused-parameter]
   14 | void init(int T) {
      |           ~~~~^
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from scales.cpp:2:
scales.cpp: In function 'void orderCoins()':
scales.cpp:96:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |     assert(best < p.size());
      |            ~~~~~^~~~~~~~~~
scales.cpp:117:38: warning: '_d' may be used uninitialized in this function [-Wmaybe-uninitialized]
  117 |       for(auto &tmp : p) if (ask_four(_a, _b, _c, _d, tmp) == result) {
      |                              ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
scales.cpp:117:38: warning: '_c' may be used uninitialized in this function [-Wmaybe-uninitialized]
scales.cpp:117:38: warning: '_b' may be used uninitialized in this function [-Wmaybe-uninitialized]
scales.cpp:117:38: warning: '_a' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Execution timed out 1061 ms 348 KB Time limit exceeded
2 Execution timed out 1027 ms 344 KB Time limit exceeded
3 Execution timed out 1071 ms 348 KB Time limit exceeded
4 Execution timed out 1056 ms 344 KB Time limit exceeded
5 Execution timed out 1070 ms 348 KB Time limit exceeded
6 Execution timed out 1038 ms 348 KB Time limit exceeded
7 Execution timed out 1054 ms 348 KB Time limit exceeded
8 Execution timed out 1035 ms 344 KB Time limit exceeded
9 Execution timed out 1091 ms 344 KB Time limit exceeded
10 Execution timed out 1067 ms 348 KB Time limit exceeded
11 Execution timed out 1082 ms 348 KB Time limit exceeded
12 Execution timed out 1042 ms 344 KB Time limit exceeded
13 Execution timed out 1016 ms 344 KB Time limit exceeded
14 Execution timed out 1038 ms 348 KB Time limit exceeded
15 Execution timed out 1047 ms 344 KB Time limit exceeded
16 Execution timed out 1030 ms 344 KB Time limit exceeded
17 Execution timed out 1044 ms 344 KB Time limit exceeded
18 Execution timed out 1018 ms 344 KB Time limit exceeded
19 Execution timed out 1065 ms 348 KB Time limit exceeded
20 Execution timed out 1073 ms 348 KB Time limit exceeded
21 Execution timed out 1008 ms 344 KB Time limit exceeded
22 Execution timed out 1041 ms 344 KB Time limit exceeded
23 Execution timed out 1040 ms 344 KB Time limit exceeded
24 Execution timed out 1086 ms 348 KB Time limit exceeded
25 Execution timed out 1065 ms 348 KB Time limit exceeded
26 Execution timed out 1094 ms 344 KB Time limit exceeded
27 Execution timed out 1075 ms 348 KB Time limit exceeded
28 Execution timed out 1057 ms 348 KB Time limit exceeded
29 Execution timed out 1058 ms 348 KB Time limit exceeded
30 Execution timed out 1061 ms 348 KB Time limit exceeded
31 Execution timed out 1006 ms 344 KB Time limit exceeded
32 Execution timed out 1058 ms 348 KB Time limit exceeded
33 Execution timed out 1071 ms 348 KB Time limit exceeded
34 Execution timed out 1066 ms 348 KB Time limit exceeded
35 Execution timed out 1028 ms 348 KB Time limit exceeded
36 Execution timed out 1059 ms 348 KB Time limit exceeded
37 Execution timed out 1022 ms 344 KB Time limit exceeded
38 Execution timed out 1045 ms 348 KB Time limit exceeded
39 Execution timed out 1075 ms 348 KB Time limit exceeded
40 Execution timed out 1020 ms 344 KB Time limit exceeded