結果
問題 | No.624 Santa Claus and The Last Dungeon |
ユーザー | pekempey |
提出日時 | 2017-12-24 17:05:00 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 45 ms / 2,000 ms |
コード長 | 3,924 bytes |
コンパイル時間 | 1,441 ms |
コンパイル使用メモリ | 114,548 KB |
実行使用メモリ | 25,464 KB |
平均クエリ数 | 382.47 |
最終ジャッジ日時 | 2024-07-16 15:10:22 |
合計ジャッジ時間 | 4,967 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
24,440 KB |
testcase_01 | AC | 42 ms
25,208 KB |
testcase_02 | AC | 43 ms
25,208 KB |
testcase_03 | AC | 43 ms
24,568 KB |
testcase_04 | AC | 42 ms
24,824 KB |
testcase_05 | AC | 44 ms
24,952 KB |
testcase_06 | AC | 45 ms
24,824 KB |
testcase_07 | AC | 44 ms
24,184 KB |
testcase_08 | AC | 45 ms
25,208 KB |
testcase_09 | AC | 45 ms
24,440 KB |
testcase_10 | AC | 43 ms
25,208 KB |
testcase_11 | AC | 44 ms
25,464 KB |
testcase_12 | AC | 42 ms
24,824 KB |
testcase_13 | AC | 45 ms
24,568 KB |
testcase_14 | AC | 44 ms
24,568 KB |
testcase_15 | AC | 43 ms
24,824 KB |
testcase_16 | AC | 42 ms
24,568 KB |
testcase_17 | AC | 44 ms
24,824 KB |
testcase_18 | AC | 42 ms
24,824 KB |
testcase_19 | AC | 43 ms
24,824 KB |
testcase_20 | AC | 43 ms
24,808 KB |
testcase_21 | AC | 45 ms
24,440 KB |
testcase_22 | AC | 44 ms
24,952 KB |
testcase_23 | AC | 41 ms
24,440 KB |
testcase_24 | AC | 43 ms
24,440 KB |
testcase_25 | AC | 43 ms
24,568 KB |
testcase_26 | AC | 41 ms
24,556 KB |
testcase_27 | AC | 42 ms
24,824 KB |
testcase_28 | AC | 42 ms
24,824 KB |
testcase_29 | AC | 43 ms
24,440 KB |
testcase_30 | AC | 43 ms
24,824 KB |
testcase_31 | AC | 44 ms
24,824 KB |
testcase_32 | AC | 43 ms
24,824 KB |
testcase_33 | AC | 43 ms
24,824 KB |
testcase_34 | AC | 43 ms
25,208 KB |
testcase_35 | AC | 43 ms
24,824 KB |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <random> #include <array> #include <queue> #include <tuple> #include <cstdlib> using namespace std; int a[100]; vector<string> ans; int query_count = 0; #ifdef LOCAL array<int, 3> ask(vector<string> q) { array<int, 3> res = {}; for (int i = 0; i < 100; i++) { int hit = 0; hit += q[i][0] - '0' == a[i] / 10; hit += q[i][1] - '0' == a[i] % 10; res[hit]++; } query_count++; return res; } #else 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; } #endif 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] == '9' ? '0' : ans[pos[i]][0] + 1; 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) { queue<tuple<int, int, int>> q; 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, "??"); #ifdef LOCAL mt19937 mt(17); for (int i = 0; i < 100; i++) { a[i] = i; } shuffle(a, a + 100, mt); #else int q; cin >> q; #endif 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); } #ifdef LOCAL for (int i = 0; i < 100; i++) { printf("%02d %s\n", a[i], ans[i].c_str()); } cout << "query count" << query_count << endl; #endif 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); 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; } int m = (l + r) / 2; int ll = -1, rr, cc; while (!q.empty()) { int l1, r1, c1; tie(l1, r1, c1) = q.front(); q.pop(); if (r1 - l1 == c1) { for (int i = l1; i < r1; i++) { ans[pos[i]][1] = v + '0'; } continue; } ll = l1; rr = r1; cc = c1; break; } 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 mm = (ll + rr) / 2; 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); } } } #ifdef LOCAL for (int i = 0; i < 100; i++) { printf("%02d %s\n", a[i], ans[i].c_str()); } cout << "query count" << query_count << endl; #else ask(ans); #endif }