結果
問題 | No.624 Santa Claus and The Last Dungeon |
ユーザー |
|
提出日時 | 2017-12-24 17:05:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 36 |
ソースコード
#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 LOCALarray<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;}#elsearray<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;}#endifint 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 LOCALmt19937 mt(17);for (int i = 0; i < 100; i++) {a[i] = i;}shuffle(a, a + 100, mt);#elseint q;cin >> q;#endiffor (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 LOCALfor (int i = 0; i < 100; i++) {printf("%02d %s\n", a[i], ans[i].c_str());}cout << "query count" << query_count << endl;#endiffor (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 LOCALfor (int i = 0; i < 100; i++) {printf("%02d %s\n", a[i], ans[i].c_str());}cout << "query count" << query_count << endl;#elseask(ans);#endif}