結果
| 問題 | No.3418 【絶望】30個並列ごちゃ混ぜHit&Blowで遊ぼう! |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-25 12:57:20 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 405 ms / 5,000 ms |
| コード長 | 4,498 bytes |
| 記録 | |
| コンパイル時間 | 2,136 ms |
| コンパイル使用メモリ | 197,392 KB |
| 実行使用メモリ | 25,972 KB |
| スコア | 9,990,658 |
| 平均クエリ数 | 93.42 |
| 最終ジャッジ日時 | 2025-12-25 12:58:22 |
| 合計ジャッジ時間 | 39,213 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 100 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <random>
#include <chrono>
using namespace std;
struct Result {
int h, b;
};
struct Guess {
int d[5];
int mask;
};
inline Result get_hb(const Guess& q, const Guess& t) {
int h = (q.d[0] == t.d[0]) + (q.d[1] == t.d[1]) + (q.d[2] == t.d[2]) + (q.d[3] == t.d[3]) + (q.d[4] == t.d[4]);
return {h, __builtin_popcount(q.mask & t.mask) - h};
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
auto start_time = chrono::steady_clock::now();
vector<Guess> all;
all.reserve(30240);
for (int i = 0; i <= 99999; i++) {
int tmp = i, m = 0, digs[5];
bool ok = true;
for (int j = 4; j >= 0; j--) {
digs[j] = tmp % 10;
if (m & (1 << digs[j])) ok = false;
m |= (1 << digs[j]);
tmp /= 10;
}
if (ok) {
Guess g; g.mask = m;
for (int j = 0; j < 5; j++) g.d[j] = digs[j];
all.push_back(g);
}
}
vector<int> candidates;
candidates.reserve(all.size());
for (int i = 0; i < (int)all.size(); i++) candidates.push_back(i);
vector<bool> used(all.size(), false);
int found = 0;
int turn = 0;
mt19937 rng(42);
while (found < 30) {
int best = -1;
auto now = chrono::steady_clock::now();
int elapsed = chrono::duration_cast<chrono::milliseconds>(now - start_time).count();
if (turn == 0) {
for (int i = 0; i < (int)all.size(); i++) {
if (all[i].d[0] == 0 && all[i].d[1] == 1 && all[i].d[2] == 2 && all[i].d[3] == 3 && all[i].d[4] == 4) {
best = i; break;
}
}
} else if (turn == 1 && found < 15) {
for (int i = 0; i < (int)all.size(); i++) {
if (all[i].d[0] == 5 && all[i].d[1] == 6 && all[i].d[2] == 7 && all[i].d[3] == 8 && all[i].d[4] == 9) {
best = i; break;
}
}
} else if (candidates.size() <= (size_t)(30 - found) || elapsed > 4500) {
for (int c : candidates) {
if (!used[c]) { best = c; break; }
}
} else {
double max_e = -1.0;
int samples = min((int)candidates.size(), 500);
auto search_start = chrono::steady_clock::now();
int limit = (elapsed < 3000) ? 250 : 120;
for (int a = 0; a < 500; a++) {
if (a % 10 == 0 && chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - search_start).count() > limit) break;
int idx = (rng() % 10 < 8) ? candidates[rng() % candidates.size()] : rng() % all.size();
if (used[idx]) continue;
int counts[6][6] = {0};
for (int i = 0; i < samples; i++) {
Result r = get_hb(all[idx], all[candidates[rng() % candidates.size()]]);
counts[r.h][r.b]++;
}
double e = 0;
for (int h = 0; h <= 5; h++) {
for (int b = 0; b <= 5; b++) {
if (counts[h][b] > 0) {
double p = (double)counts[h][b] / samples;
e -= p * log2(p);
}
}
}
if (e > max_e) {
max_e = e;
best = idx;
}
}
}
if (best == -1) {
for (int i = 0; i < (int)all.size(); i++) if (!used[i]) { best = i; break; }
}
used[best] = true;
for (int i = 0; i < 5; i++) cout << all[best].d[i];
cout << endl;
int res_map[6][6] = {0};
for (int i = 0; i < 30; i++) {
int h, b;
if (!(cin >> h >> b)) return 0;
if (h == -1) return 0;
res_map[h][b]++;
}
found = res_map[5][0];
if (found == 30) break;
vector<int> next_c;
next_c.reserve(candidates.size());
for (int idx : candidates) {
if (idx == best) continue;
Result r = get_hb(all[best], all[idx]);
if (r.h == 5 && r.b == 0) continue;
if (res_map[r.h][r.b] > 0) {
next_c.push_back(idx);
}
}
candidates = move(next_c);
turn++;
}
return 0;
}