結果
| 問題 | No.3418 【絶望】30個並列ごちゃ混ぜHit&Blowで遊ぼう! |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-25 13:11:21 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 375 ms / 5,000 ms |
| コード長 | 4,715 bytes |
| 記録 | |
| コンパイル時間 | 2,160 ms |
| コンパイル使用メモリ | 197,972 KB |
| 実行使用メモリ | 26,228 KB |
| スコア | 9,992,334 |
| 平均クエリ数 | 76.66 |
| 最終ジャッジ日時 | 2025-12-25 13:12:01 |
| 合計ジャッジ時間 | 39,557 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 100 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <random>
#include <chrono>
using namespace std;
typedef uint8_t ResultCode;
struct Guess {
int d[5];
int mask;
};
inline ResultCode get_hb_code(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]);
int b = __builtin_popcount(q.mask & t.mask) - h;
return (ResultCode)(h * 6 + b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
auto start_time = chrono::steady_clock::now();
auto get_ms = [&]() {
return chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start_time).count();
};
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; break; }
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;
for (int i = 0; i < (int)all.size(); i++) candidates.push_back(i);
vector<bool> is_target_found(all.size(), false);
int found_count = 0;
mt19937 rng(42);
double log_table[30241];
for (int i = 0; i <= 30240; i++) log_table[i] = (i <= 1) ? 0 : log2(i);
while (found_count < 30) {
int best_idx = -1;
if (found_count == 0 && candidates.size() == 30240) {
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_idx = i; break;
}
}
}
else if (candidates.size() <= (size_t)(30 - found_count)) {
for (int c : candidates) {
if (!is_target_found[c]) { best_idx = c; break; }
}
}
else {
double max_entropy = -1.0;
long long time_limit = 4800 - get_ms();
int turn_limit = (candidates.size() > 1500) ? 500 : 2000;
auto search_start = chrono::steady_clock::now();
int sample_n = min((int)candidates.size(), 700);
vector<int> sample_c;
if (candidates.size() <= (size_t)sample_n) sample_c = candidates;
else {
for (int i = 0; i < sample_n; i++) sample_c.push_back(candidates[rng() % candidates.size()]);
}
for (int i = 0; i < turn_limit; i++) {
if ((i & 31) == 0) {
if (chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - search_start).count() > (time_limit / 8)) break;
}
int q_idx = (rng() % 10 < 8) ? candidates[rng() % candidates.size()] : rng() % all.size();
if (is_target_found[q_idx]) continue;
int counts[36] = {0};
for (int c_idx : sample_c) {
counts[get_hb_code(all[q_idx], all[c_idx])]++;
}
double entropy = 0;
for (int j = 0; j < 36; j++) {
if (counts[j] > 0) {
entropy -= (double)counts[j] * log_table[counts[j]];
}
}
if (entropy > max_entropy) {
max_entropy = entropy;
best_idx = q_idx;
}
}
}
if (best_idx == -1) best_idx = candidates[0];
for (int i = 0; i < 5; i++) cout << all[best_idx].d[i];
cout << endl;
int res_freq[36] = {0};
for (int i = 0; i < 30; i++) {
int h, b;
if (!(cin >> h >> b)) return 0;
if (h == -1) return 0;
res_freq[h * 6 + b]++;
}
if (res_freq[30] > found_count) {
is_target_found[best_idx] = true;
found_count = res_freq[30];
}
if (found_count == 30) break;
int active_30 = res_freq[30] - (found_count - (is_target_found[best_idx] ? 1 : 0));
res_freq[30] = max(0, active_30);
vector<int> next_c;
next_c.reserve(candidates.size());
for (int c_idx : candidates) {
if (is_target_found[c_idx]) continue;
if (res_freq[get_hb_code(all[best_idx], all[c_idx])] > 0) {
next_c.push_back(c_idx);
}
}
candidates = move(next_c);
}
return 0;
}