結果

問題 No.1152 10億ゲーム
ユーザー 👑 emthrmemthrm
提出日時 2020-08-09 01:15:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 2,175 bytes
コンパイル時間 2,369 ms
コンパイル使用メモリ 194,540 KB
最終ジャッジ日時 2025-01-12 19:13:46
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

pair<int, int> f(int x) {
  int a = 0, b = 0;
  while (x % 2 == 0) {
    ++a;
    x /= 2;
  }
  while (x % 5 == 0) {
    ++b;
    x /= 5;
  }
  return {a, b};
}

int g(pair<int, int> p) {
  auto [a, b] = p;
  int res = 1;
  REP(_, a) res *= 2;
  REP(_, b) res *= 5;
  return res;
}

int dist(pair<int, int> p1, pair<int, int> p2) {
  return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}

int main() {
  int x1, x2; cin >> x1 >> x2;
  auto p1 = f(x1);
  while (p1.first != 7) {
    p1.first += p1.first > 7 ? -1 : 1;
    x1 = g(p1);
    cout << x1 << endl;
    if (x1 == x2) return 0;
    cin >> x2;
    if (x1 == x2) return 0;
  }
  while (p1.second != 9) {
    ++p1.second;
    x1 = g(p1);
    cout << x1 << endl;
    if (x1 == x2) return 0;
    cin >> x2;
    if (x1 == x2) return 0;
  }
  auto p2 = f(x2);
  if (dist(p1, p2) & 1) {
    x1 = 500000000;
    cout << x1 << endl;
    if (x1 == x2) return 0;
    cin >> x2;
    if (x1 == x2) return 0;
  }
  x1 = 1000000000;
  p1 = {9, 9};
  cout << x1 << endl;
  if (x1 == x2) return 0;
  cin >> x2;
  if (x1 == x2) return 0;
  p2 = f(x2);
  while (true) {
    (p1.first - p2.first > p1.second - p2.second ? p1.first : p1.second) -= 1;
    x1 = g(p1);
    cout << x1 << endl;
    if (x1 == x2) return 0;
    cin >> x2;
    p2 = f(x2);
    if (x1 == x2) return 0;
  }
}
0