結果

問題 No.624 Santa Claus and The Last Dungeon
ユーザー pekempeypekempey
提出日時 2017-12-24 17:30:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 3,082 bytes
コンパイル時間 1,204 ms
コンパイル使用メモリ 112,204 KB
実行使用メモリ 24,384 KB
平均クエリ数 382.47
最終ジャッジ日時 2023-09-23 15:25:47
合計ジャッジ時間 4,867 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
23,412 KB
testcase_01 AC 44 ms
23,652 KB
testcase_02 AC 44 ms
23,832 KB
testcase_03 AC 44 ms
23,820 KB
testcase_04 AC 45 ms
23,604 KB
testcase_05 AC 44 ms
24,012 KB
testcase_06 AC 44 ms
23,988 KB
testcase_07 AC 46 ms
24,336 KB
testcase_08 AC 46 ms
23,592 KB
testcase_09 AC 45 ms
24,000 KB
testcase_10 AC 44 ms
23,880 KB
testcase_11 AC 45 ms
23,640 KB
testcase_12 AC 43 ms
23,640 KB
testcase_13 AC 43 ms
24,072 KB
testcase_14 AC 45 ms
23,412 KB
testcase_15 AC 45 ms
24,096 KB
testcase_16 AC 45 ms
24,072 KB
testcase_17 AC 46 ms
23,604 KB
testcase_18 AC 45 ms
24,084 KB
testcase_19 AC 45 ms
23,964 KB
testcase_20 AC 46 ms
23,532 KB
testcase_21 AC 45 ms
23,628 KB
testcase_22 AC 45 ms
24,036 KB
testcase_23 AC 42 ms
23,988 KB
testcase_24 AC 45 ms
23,364 KB
testcase_25 AC 44 ms
23,640 KB
testcase_26 AC 43 ms
24,384 KB
testcase_27 AC 44 ms
23,484 KB
testcase_28 AC 42 ms
23,604 KB
testcase_29 AC 44 ms
23,880 KB
testcase_30 AC 43 ms
23,988 KB
testcase_31 AC 45 ms
23,388 KB
testcase_32 AC 44 ms
23,532 KB
testcase_33 AC 44 ms
23,592 KB
testcase_34 AC 42 ms
23,364 KB
testcase_35 AC 44 ms
24,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <random>
#include <array>
#include <queue>
#include <tuple>
#include <cstdlib>

using namespace std;

vector<string> ans;

array<int, 3> ask(vector<string> q) {
  for (int i = 0; i < q.size(); i++) {
    if (i != 0) cout << ' ';
    cout << q[i];
  }
  cout << endl;
  array<int, 3> res;
  for (int i = 0; i < 3; i++) {
    cin >> res[i];
  }
  if (res[2] == 100) {
    exit(0);
  }
  return res;
}

int ask_uniform(int val, const vector<int> &pos, int l, int r, bool low) {
  vector<string> query(100, "??"); 
  for (int i = l; i < r; i++) {
    query[pos[i]][low] = val + '0';
  }
  return ask(query)[1];
}

pair<int, int> ask_uniform2(int v, const vector<int> &pos, int l0, int r0, int l1, int r1) {
  vector<string> query(100, "??"); 
  for (int i = l0; i < r0; i++) {
    query[pos[i]][0] = (ans[pos[i]][0] - '0' + 1) % 10 + '0';
    query[pos[i]][1] = v + '0';
  }
  for (int i = l1; i < r1; i++) {
    query[pos[i]][0] = ans[pos[i]][0];
    query[pos[i]][1] = v + '0';
  }
  auto res = ask(query);
  return {res[1] - (r1 - l1 - res[2]), res[2]};
}

void rec(const vector<int> &pos, int l, int r, int v, int c, bool low) {
  if (c == 0) return;
  if (r - l == c) {
    for (int i = l; i < r; i++) {
      ans[pos[i]][low] = v + '0';
    }
    return;
  }
  int m = (l + r) / 2;
  int c0 = ask_uniform(v, pos, l, m, low);
  int c1 = c - c0;
  rec(pos, l, m, v, c0, low);
  rec(pos, m, r, v, c1, low);
}

int main() {
  ans.resize(100, "??");
  int q;
  cin >> q;

  for (int i = 0; i < 10; i++) {
    vector<int> pos;
    for (int k = 0; k < 100; k++) {
      if (ans[k][0] == '?') {
        pos.push_back(k);
      }
    }
    rec(pos, 0, pos.size(), i, 10, false);
  }

  for (int v = 0; v < 10; v++) {
    vector<int> pos;
    for (int k = 0; k < 100; k++) {
      if (ans[k][1] == '?') {
        pos.push_back(k);
      }
    }
    queue<tuple<int, int, int>> q;
    q.emplace(0, pos.size(), 10);
    auto get = [&]() -> tuple<int, int, int> {
      while (!q.empty()) {
        int l, r, c;
        tie(l, r, c) = q.front(); q.pop();
        if (r - l == c) {
          for (int i = l; i < r; i++) {
            ans[pos[i]][1] = v + '0';
          }
          continue;
        }
        return make_tuple(l, r, c);
      }
      return make_tuple(-1, -1, -1);
    };
    while (true) {
      int l, r, c;
      int ll, rr, cc;
      tie(l, r, c) = get();
      tie(ll, rr, cc) = get();
      if (l == -1) break;
      int m = (l + r) / 2;
      int mm = (ll + rr) / 2;
      if (ll == -1) {
        int c0 = ask_uniform(v, pos, l, m, true);
        int c1 = c - c0;
        if (c0 > 0) q.emplace(l, m, c0);
        if (c1 > 0) q.emplace(m, r, c1);
      } else {
        int c0, cc0;
        tie(c0, cc0) = ask_uniform2(v, pos, l, m, ll, mm);
        int c1 = c - c0;
        int cc1 = cc - cc0;
        if (c0 > 0) q.emplace(l, m, c0);
        if (c1 > 0) q.emplace(m, r, c1);
        if (cc0 > 0) q.emplace(ll, mm, cc0);
        if (cc1 > 0) q.emplace(mm, rr, cc1);
      }
    }
  }
  
  ask(ans);
}
0