結果
| 問題 | No.1152 10億ゲーム |
| コンテスト | |
| ユーザー |
komakoko
|
| 提出日時 | 2026-05-14 00:05:18 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,094 bytes |
| 記録 | |
| コンパイル時間 | 4,592 ms |
| コンパイル使用メモリ | 380,652 KB |
| 実行使用メモリ | 59,768 KB |
| 平均クエリ数 | 0.04 |
| 最終ジャッジ日時 | 2026-05-14 00:05:50 |
| 合計ジャッジ時間 | 9,328 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 TLE * 1 -- * 47 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define rep1(i, n) for(ll i = 1; i <= (ll)(n); ++i)
#define rrep(i, n) for(ll i = (ll)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for(ll i = (ll)(n); i >= 1; --i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#ifdef DEBUG
#define dbg if(true)
#else
#define dbg if(false)
#endif
template<typename T> bool chmin(T &a, const T &b) {if(a>b) {a=b; return true;} return false;}
template<typename T> bool chmax(T &a, const T &b) {if(a<b) {a=b; return true;} return false;}
template <typename T> void print(const T &a) {cout << a << '\n';}
template <typename T> void print(const vector<T> &v1) {for(int i=0; i<v1.size(); ++i){if(i) {cout << ' ';} cout << v1[i];} cout << '\n';}
template <typename T> void print(const vector<vector<T>> &v2) {for(int i=0; i<v2.size(); ++i) print(v2[i]); cout << '\n';}
template<typename T>
struct pair_hash {
size_t operator()(const pair<long long, long long>& p) const {
size_t h1 = hash<long long>{}(p.first);
size_t h2 = hash<long long>{}(p.second);
return h1 ^ (h2 + 0x9e3779b9 + (h1 << 6) + (h1 >> 2));
}
};
void solve() {
auto f = [&] (ll i, ll x) -> ll {
ll res = -1;
if(i == 0) if(x >= 2 && x % 2 == 0) res = x / 2;
if(i == 1) if(x >= 5 && x % 5 == 0) res = x / 5;
if (i == 2) res = min(2 * x, 1000000000LL);
if (i == 3) res = min(5 * x, 1000000000LL);
if(x == res) return -1;
if(1000000000LL % res != 0) return -1;
return res;
};
unordered_map<pair<ll, ll>, ll, pair_hash<ll>> mp;
rep(koma2, 10) rep(koma5, 10) rep(kiri2, 10) rep(kiri5, 10) {
ll komaval = 1; rep(i, koma2) komaval *= 2; rep(i, koma5) komaval *= 5;
ll kirival = 1; rep(i, kiri2) kirival *= 2; rep(i, kiri5) kirival *= 5;
if(komaval == kirival) mp[{komaval, kirival}] = 0;
else if(abs(koma2 - kiri2) + abs(koma5 - kiri5) == 1) mp[{komaval, kirival}] = 1;
else mp[{komaval, kirival}] = 1LL<<60;
}
rep(turn, 35) {
for(const auto& [key, val] : mp) {
const auto& [komaval, kirival] = key;
ll best = 1LL<<60;
rep(komai, 4) {
if (f(komai, komaval) == -1) continue;
ll kiriworst = 0;
rep(kirii, 4) if(f(kirii, kirival) != -1) chmax(kiriworst, mp[{f(komai, komaval), f(kirii, kirival)}]);
chmin(best, kiriworst);
}
chmin(mp.at({komaval, kirival}), best);
}
}
ll komaval, kirival; cin >> komaval >> kirival;
while(true) {
if(komaval == kirival) return;
ll next = 0; ll bestcost = 1LL<<60;
rep(i, 4) if(f(i, komaval) != -1) if(chmin(bestcost, mp[{f(i, komaval), kirival}])) next = f(i, komaval);
cout << next << endl;
komaval = next;
if(komaval == kirival) return;
cin >> kirival;
}
return;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int test_case = 1;
// cin >> test_case;
// cout << std::setprecision(15);
while (test_case--) {
solve();
}
return 0;
}
komakoko