結果

問題 No.282 おもりと天秤(2)
ユーザー kk
提出日時 2021-03-23 12:27:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,308 bytes
コンパイル時間 2,502 ms
コンパイル使用メモリ 214,024 KB
実行使用メモリ 24,528 KB
平均クエリ数 427.42
最終ジャッジ日時 2023-09-24 02:54:53
合計ジャッジ時間 11,612 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,424 KB
testcase_01 AC 40 ms
23,628 KB
testcase_02 AC 28 ms
24,408 KB
testcase_03 AC 29 ms
23,472 KB
testcase_04 AC 27 ms
23,436 KB
testcase_05 AC 32 ms
24,120 KB
testcase_06 AC 48 ms
24,084 KB
testcase_07 AC 26 ms
23,604 KB
testcase_08 AC 47 ms
23,712 KB
testcase_09 AC 26 ms
23,580 KB
testcase_10 AC 1,383 ms
23,292 KB
testcase_11 TLE -
testcase_12 AC 1,575 ms
23,892 KB
testcase_13 AC 2,632 ms
24,072 KB
testcase_14 AC 4,493 ms
24,432 KB
testcase_15 TLE -
testcase_16 AC 299 ms
24,528 KB
testcase_17 AC 2,332 ms
24,108 KB
testcase_18 AC 4,123 ms
24,408 KB
testcase_19 AC 4,134 ms
24,084 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

void output(const vector<int> &v) {
  cout << "!";
  for (int x: v)
    cout << " " << x+1;
  cout << endl;
  cout.flush();
}

vector<char> query(const vector<int> &v, int n) {
  cout << "?";
  for (int x: v)
    cout << " " << x + 1;
  cout << endl;
  cout.flush();
  vector<char> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  return s;
}

vector<int> make(const set<int> &lo, const set<int> &hi, int n) {
  vector<int> cand;
  vector<int> vis(n);
  for (int x: lo) {
    if (!vis[x]) {
      vis[x] = 1;
      cand.push_back(x);
    }
  }
  if (cand.size() % 2)
    cand.push_back(-1);
  for (int x: hi) {
    if (!vis[x]) {
      vis[x] = 1;
      cand.push_back(x);
    }
  }
  while (cand.size() < 2 * n)
    cand.push_back(-1);
  return cand;  
}

set<int> cross(const set<int> &a, const set<int> &b) {
  set<int> c;
  for (int x: a) {
    if (b.count(x))
      c.insert(x);
  }
  return c;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  vector<int> fixed(n);
  vector<int> ret(n);

  int s = 0, t = n-1;
  while (s <= t) {
    set<int> lo, hi;
    for (int i = 0; i < n; i++) {
      if (!fixed[i]) {
        lo.insert(i);
        hi.insert(i);
      }
    }

    while (lo.size() > 1 || hi.size() > 1) {
      vector<int> cand = make(lo, hi, n);
      vector<char> ans = query(cand, n);
      set<int> lo_t, hi_t;
      for (int i = 0; i < ans.size(); i++) {
        if (ans[i] == '<') {
          if (cand[2*i] == -1 && cand[2*i+1] == -1) {}
          else if (cand[2*i+1] == -1) {
            lo_t.insert(cand[2*i]);
            hi_t.insert(cand[2*i]);
          } else {
            lo_t.insert(cand[2*i]);
            hi_t.insert(cand[2*i+1]);
          }
        } else if (ans[i] == '>') {
          if (cand[2*i] == -1 && cand[2*i+1] == -1) {}
          else if (cand[2*i+1] == -1) {
            lo_t.insert(cand[2*i]);
            hi_t.insert(cand[2*i]);
          } else {
            lo_t.insert(cand[2*i+1]);
            hi_t.insert(cand[2*i]);
          }
        }
      }
      hi = cross(hi, hi_t);
      lo = cross(lo, lo_t);
    }

    ret[s++] = *lo.begin();
    ret[t--] = *hi.begin();
    fixed[*lo.begin()] = 1;
    fixed[*hi.begin()] = 1;
  }

  output(ret);
  
  return 0;
}
0