結果

問題 No.1152 10億ゲーム
コンテスト
ユーザー coindarw
提出日時 2026-05-13 03:31:36
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 9,392 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,373 ms
コンパイル使用メモリ 391,672 KB
実行使用メモリ 30,052 KB
平均クエリ数 23.00
最終ジャッジ日時 2026-05-13 03:31:52
合計ジャッジ時間 11,684 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#ifdef ONLINE_JUDGE
#include <bits/stdc++.h>

#include <atcoder/all>
#else
#include <mylibs/all.h>
#endif

using ll = long long;
using lll = __int128_t;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n) - 1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define length(v) ((int)(v).size())
constexpr int inf = 2'000'000'000;
constexpr ll linf = 4'000'000'000'000'000'000, M7 = 1'000'000'007, M9 = 998'244'353;
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
using namespace std;
using namespace atcoder;

// clang-format off
using vint = vector<int>;using vvint = vector<vector<int>>;using vvvint = vector<vector<vector<int>>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;using vvvll = vector<vector<vector<ll>>>;
using vlll = vector<lll>;using vvlll = vector<vector<lll>>;using vvvlll = vector<vector<vector<lll>>>;
using vchar = vector<char>;using vvchar = vector<vector<char>>;using vvvchar = vector<vector<vector<char>>>;
using vstr = vector<string>;using vvstr = vector<vector<string>>;using vvvstr = vector<vector<vector<string>>>;
using vpi = vector<pair<int, int>>;using vvpi = vector<vector<pair<int, int>>>;using vvpint = vector<vector<pair<int, int>>>;
using vpl = vector<pair<ll, ll>>;using vvpl = vector<vector<pair<ll, ll>>>;using vvplint = vector<vector<pair<ll, int>>>;
using vbool = vector<bool>;using vvbool = vector<vector<bool>>;using vvvbool = vector<vector<vector<bool>>>;

#define Vec(type, ...) __make_vec<type>(__VA_ARGS__)
template <class T> vector<T> __make_vec(size_t a) {return vector<T>(a);}template <class T, class... Ts>
auto __make_vec(size_t a, Ts... ts) {return vector<decltype(__make_vec<T>(ts...))>(a, __make_vec<T>(ts...));}
#define VecI(init, type, ...) __make_vecI<type, init>(__VA_ARGS__)
template <class T, T init>vector<T> __make_vecI(size_t a) {return vector<T>(a, init);}
template <class T, T init, class... Ts>
auto __make_vecI(size_t a, Ts... ts) {return vector<decltype(__make_vecI<T, init>(ts...))>(a, __make_vecI<T, init>(ts...));}

template <typename T, typename U>inline ostream& operator<<(ostream& os, const pair<T, U>& p) noexcept {return os << p.first << " " << p.second;}
inline ostream& operator<<(ostream& os, const modint& m) noexcept { return os << m.val(); }
template <int M>inline ostream& operator<<(ostream& os, const static_modint<M>& m) noexcept { return os << m.val(); }

template <typename T> struct is_static_modint : std::false_type {}; template <int MOD> struct is_static_modint<static_modint<MOD>> : std::true_type {};
template <template <typename...> typename C, typename Number>concept MyContainer = std::is_same_v<C<Number>, std::vector<Number>> || std::is_same_v<C<Number>, std::deque<Number>> || std::is_same_v<C<Number>, std::set<Number>> || std::is_same_v<C<Number>, std::unordered_set<Number>> || std::is_same_v<C<Number>, std::unordered_multiset<Number>> || std::is_same_v<C<Number>, std::multiset<Number>>;
template <typename Number>concept MyNumber = std::is_same_v<Number, int> || std::is_same_v<Number, ll> || std::is_same_v<Number, char> || std::is_same_v<Number, modint> || is_static_modint<Number>::value;
template <template <typename...> typename C, typename Number>concept MyContainerNumber = MyContainer<C, Number> && MyNumber<Number>;
template <template <typename...> typename OutCon, template <typename...> typename InCon, typename Number>concept MyNestedContainerNumber = MyContainer<OutCon, InCon<Number>> && MyContainerNumber<InCon, Number>;
template <template <typename...> typename C, typename Number>requires MyContainerNumber<C, Number>std::ostream& operator<<(std::ostream& os, const C<Number>& t) {auto itr = t.begin();auto end = t.end();if (itr != end) {os << *itr++;for (; itr != end; ++itr) os << ' ' << *itr;}return os;}
template <template <typename...> typename OutCon, template <typename...> typename InCon, typename Number>requires MyNestedContainerNumber<OutCon, InCon, Number>std::ostream& operator<<(std::ostream& os, const OutCon<InCon<Number>>& t) {auto itr = t.begin();auto end = t.end();if (itr != end) {os << *itr++;for (; itr != end; ++itr) os << '\n' << *itr;}return os;}
template <typename T, typename U>istream& operator>>(istream& is, pair<T, U>& p) {return is >> p.first >> p.second;}
template <typename T>istream& operator>>(istream& is, vector<T>& v) {for (auto& e : v) is >> e;return is;}
void inp() {}
template <typename T, typename... Args>void inp(T& a, Args&... args) {cin >> a, inp(args...);}
template <typename T>void inp1(vector<T>& v, int offset = 1, int len = -1) {if (len == -1) len = int(v.size()) - offset;assert(offset >= 0 && len >= 0);for (int i = offset; i < offset + len; ++i) cin >> v[i];}
template <typename T>void oup(const T& a) {cout << a << "\n";}
template <typename T, typename... Args>void oup(const T& a, const Args&... args) {cout << a << " ", oup(args...);}
template <typename T>void oupl(const T& a) {cout << a;}
template <typename T, typename... Args>void oupl(const T& a, const Args&... args) {cout << a << " ", oupl(args...);}


inline string YesNo(bool cond) { return cond ? "Yes" : "No"; }
inline auto add1(auto vec, ll offset = 1) {for (auto& e : vec) e += offset;return vec;}
#ifdef ONLINE_JUDGE
#define debug(...)
#else
#define debug(...) cerr << "<" << #__VA_ARGS__ << ">: ", debug_out(__VA_ARGS__)
template <typename T>void debug_out(T t) {cerr << t << "\n";}
template <typename T, typename... Args>void debug_out(T t, Args... args) {cerr << t << ", ";debug_out(args...);}
#endif

#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
auto minE(const auto&a) {
    return min_element(a.begin(), a.end());
}
auto maxE(const auto&a) {
    return max_element(a.begin(), a.end());
}

#ifdef ONLINE_JUDGE
#define todo(...) static_assert(false)
#else
#define todo(...)
#endif
// clang-format on

int main() {
    constexpr ll N = 1'000'000'000;

    vll div;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            div.eb(i);
            div.eb(N / i);
        }
    }
    sort(all(div));

    auto cand = [&](ll x) -> vll {
        vll ret;
        if (N % (x * 2) == 0 && x * 2 <= N) {
            ret.eb(x * 2);
        }
        if (N % (x * 5) == 0 && x * 5 <= N) {
            ret.eb(x * 5);
        }
        if (x % 2 == 0) {
            ret.eb(x / 2);
        }
        if (x % 5 == 0) {
            ret.eb(x / 5);
        }
        if (x == N / 4) {
            ret.eb(N);
        }
        return ret;
    };

    const ll m = ssize(div);
    struct edge {
        int to;
        edge(int _to) : to(_to) {}
    };
    vector<vector<edge>> revG(m * m * 2);
    auto f = [&](int i, int j, bool t) -> int { return (i * m + j) + (m * m) * t; };
    auto g = [&](int x) -> tuple<int, int, bool> {
        bool t = x / (m * m);
        x %= m * m;
        int i = x / m, j = x % m;
        return {i, j, t};
    };
    rep(i, m) rep(j, m) {
        if (i == j) continue;
        for (ll iTo : cand(div[i])) {
            int iIdx = lb(all(div), iTo) - div.begin();
            revG[f(iIdx, j, 1)].eb(f(i, j, 0));
        }
    }
    rep(i, m) rep(j, m) {
        if (i == j) continue;
        for (ll jTo : cand(div[j])) {
            int jIdx = lb(all(div), jTo) - div.begin();
            revG[f(i, jIdx, 0)].eb(f(i, j, 1));
        }
    }

    auto retrograde_analysis = [&](const auto& revG) {
        const int n = revG.size();
        vector<int> outDeg(n);
        queue<int> que;
        vint num(n, inf);
        vint nxt(n, -1);
        rep(i, n) {
            for (const auto& e : revG.at(i)) {
                outDeg.at(e.to)++;
            }
        }
        rep(i, n) {
            if (outDeg.at(i) == 0) {
                que.push(i);
                num[i] = 0;
            }
        }
        while (!que.empty()) {
            int u = que.front();
            auto [i, j, t] = g(u);
            que.pop();
            for (const auto& e : revG.at(u)) {
                int nv = e.to;
                auto [pi, pj, pt] = g(nv);
                if (num[nv] != inf) continue;
                outDeg.at(nv)--;
                if (pt) {  // 後手
                    if (outDeg.at(nv) == 0) {
                        num[nv] = num[u] + 1;
                        que.push(nv);
                        nxt[nv] = u;
                    }
                } else {  // 先手
                    if (num[u] != inf) {
                        num[nv] = num[u] + 1;
                        que.push(nv);
                        nxt[nv] = u;
                    }
                }
            }
        }
        return nxt;
    };

    auto nxt = retrograde_analysis(revG);
    ll x, y;
    inp(x, y);
    ll xi = lb(all(div), x) - div.begin();
    ll yi = lb(all(div), y) - div.begin();
    while (true) {
        int cur = f(xi, yi, 0);
        auto [x1i, y1i, t] = g(nxt[cur]);
        cout << div[x1i] << endl;
        if (x1i == y1i) {
            return 0;
        }
        ll y2;
        inp(y2);
        ll y2i = lb(all(div), y2) - div.begin();
        if (x1i == y2i) {
            return 0;
        }
        xi = x1i;
        yi = y2i;
    }
}
0