結果

問題 No.3418 【絶望】30個並列ごちゃ混ぜHit&Blowで遊ぼう!
コンテスト
ユーザー LNG
提出日時 2025-12-25 12:53:48
言語 C++23
(gcc 13.3.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 4,601 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,390 ms
コンパイル使用メモリ 195,256 KB
実行使用メモリ 26,368 KB
スコア 4,473,824
平均クエリ数 17987.08
最終ジャッジ日時 2025-12-25 12:57:58
合計ジャッジ時間 237,061 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 47 WA * 53
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <chrono>
#include <random>
#include <cmath>

using namespace std;

struct Result {
    int h, b;
    bool operator<(const Result& o) const {
        if (h != o.h) return h < o.h;
        return b < o.b;
    }
    bool operator==(const Result& o) const {
        return h == o.h && b == o.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]);
    int common = __builtin_popcount(q.mask & t.mask);
    return {h, common - h};
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    auto start_time = chrono::steady_clock::now();
    mt19937 rng(1337);

    vector<Guess> all_g;
    all_g.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_g.push_back(g);
        }
    }

    vector<int> candidates;
    candidates.reserve(all_g.size());
    for (int i = 0; i < (int)all_g.size(); i++) candidates.push_back(i);

    int turn = 0;
    while (true) {
        int best_idx = -1;
        if (turn == 0) {
            for (int i = 0; i < (int)all_g.size(); i++) {
                if (all_g[i].d[0] == 0 && all_g[i].d[1] == 1 && all_g[i].d[2] == 2 && all_g[i].d[3] == 3 && all_g[i].d[4] == 4) {
                    best_idx = i; break;
                }
            }
        } else if (turn == 1) {
            for (int i = 0; i < (int)all_g.size(); i++) {
                if (all_g[i].d[0] == 5 && all_g[i].d[1] == 6 && all_g[i].d[2] == 7 && all_g[i].d[3] == 8 && all_g[i].d[4] == 9) {
                    best_idx = i; break;
                }
            }
        } else {
            double max_e = -1.0;
            auto search_start = chrono::steady_clock::now();
            int sample_n = min((int)candidates.size(), 600);
            
            int attempts = (candidates.size() > 1000) ? 100 : 250;
            for (int a = 0; a < attempts; a++) {
                if (a % 10 == 0) {
                    auto now = chrono::steady_clock::now();
                    if (chrono::duration_cast<chrono::milliseconds>(now - search_start).count() > 400) break;
                }

                int q_idx;
                if (rng() % 10 < 7 && !candidates.empty()) {
                    q_idx = candidates[rng() % candidates.size()];
                } else {
                    q_idx = rng() % all_g.size();
                }

                int counts[6][6] = {0};
                for (int i = 0; i < sample_n; i++) {
                    int c_idx = candidates[rng() % candidates.size()];
                    Result r = get_hb(all_g[q_idx], all_g[c_idx]);
                    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] / sample_n;
                            e -= p * log2(p);
                        }
                    }
                }
                
                if (e > max_e) {
                    max_e = e;
                    best_idx = q_idx;
                }
            }
        }

        if (best_idx == -1) best_idx = candidates[0];

        for (int i = 0; i < 5; i++) cout << all_g[best_idx].d[i];
        cout << endl;

        int res_counts[6][6] = {0};
        bool all_cleared = false;
        int first_h, first_b;
        for (int i = 0; i < 30; i++) {
            int h, b;
            if (!(cin >> h >> b)) return 0;
            if (h == -1) return 0;
            if (i == 0) { first_h = h; first_b = b; }
            res_counts[h][b]++;
        }

        if (first_h == 5 && first_b == 0) break;

        vector<int> next_c;
        for (int c_idx : candidates) {
            Result r = get_hb(all_g[best_idx], all_g[c_idx]);
            if (r.h == 5 && r.b == 0) continue;
            if (res_counts[r.h][r.b] > 0) {
                next_c.push_back(c_idx);
            }
        }
        candidates = move(next_c);
        turn++;
    }

    return 0;
}
0