結果

問題 No.1152 10億ゲーム
ユーザー tnakao0123tnakao0123
提出日時 2020-08-09 04:31:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,858 bytes
コンパイル時間 892 ms
コンパイル使用メモリ 92,860 KB
実行使用メモリ 24,372 KB
平均クエリ数 26.00
最終ジャッジ日時 2023-09-24 05:27:33
合計ジャッジ時間 6,597 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
23,412 KB
testcase_01 AC 62 ms
23,364 KB
testcase_02 AC 63 ms
23,652 KB
testcase_03 AC 63 ms
23,412 KB
testcase_04 AC 61 ms
24,024 KB
testcase_05 AC 61 ms
23,604 KB
testcase_06 AC 64 ms
24,036 KB
testcase_07 AC 63 ms
24,228 KB
testcase_08 AC 60 ms
23,412 KB
testcase_09 AC 61 ms
23,832 KB
testcase_10 AC 62 ms
23,508 KB
testcase_11 AC 64 ms
23,412 KB
testcase_12 AC 64 ms
23,364 KB
testcase_13 AC 63 ms
23,616 KB
testcase_14 AC 62 ms
23,532 KB
testcase_15 AC 63 ms
23,652 KB
testcase_16 AC 64 ms
24,024 KB
testcase_17 AC 65 ms
23,376 KB
testcase_18 AC 66 ms
23,532 KB
testcase_19 AC 67 ms
23,400 KB
testcase_20 AC 66 ms
23,412 KB
testcase_21 AC 65 ms
23,808 KB
testcase_22 AC 65 ms
24,012 KB
testcase_23 AC 65 ms
23,652 KB
testcase_24 AC 66 ms
24,012 KB
testcase_25 AC 65 ms
23,652 KB
testcase_26 AC 66 ms
23,400 KB
testcase_27 AC 65 ms
24,024 KB
testcase_28 AC 65 ms
23,364 KB
testcase_29 AC 66 ms
23,628 KB
testcase_30 AC 66 ms
24,036 KB
testcase_31 AC 66 ms
23,964 KB
testcase_32 AC 66 ms
24,276 KB
testcase_33 AC 66 ms
23,376 KB
testcase_34 AC 65 ms
23,364 KB
testcase_35 AC 65 ms
23,640 KB
testcase_36 AC 66 ms
23,640 KB
testcase_37 AC 66 ms
24,360 KB
testcase_38 AC 67 ms
23,412 KB
testcase_39 AC 64 ms
23,640 KB
testcase_40 AC 63 ms
24,348 KB
testcase_41 AC 64 ms
23,400 KB
testcase_42 AC 63 ms
23,508 KB
testcase_43 AC 63 ms
23,400 KB
testcase_44 AC 65 ms
24,372 KB
testcase_45 AC 66 ms
23,640 KB
testcase_46 AC 64 ms
23,628 KB
testcase_47 AC 67 ms
24,024 KB
testcase_48 AC 64 ms
24,252 KB
testcase_49 AC 64 ms
24,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1152.cc:  No.1152 10億ゲーム - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 10;

/* typedef */

typedef long long ll;
typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

int e2s[MAX_N], e5s[MAX_N];

/* subroutines */

inline void getpos(int &x, int &y) {
  int p;
  scanf("%d", &p);
  x = y = 0;
  while (p % 2 == 0) x++, p /= 2;
  while (p % 5 == 0) y++, p /= 5;
}

inline void putpos(int x, int y) {
  printf("%d\n", e2s[x] * e5s[y]); fflush(stdout);
}

inline bool getputpos(int ax, int ay, int &bx, int &by) {
  putpos(ax, ay);
  if (ax == bx && ay == by) return true;
  getpos(bx, by);
  return (ax == bx && ay == by);
}

inline int hdist(int x0, int y0, int x1, int y1) {
  return abs(x1 - x0) + abs(y1 - y0);
}

/* main */

int main() {
  e2s[0] = e5s[0] = 1;
  for (int i = 1; i < MAX_N; i++) {
    e2s[i] = e2s[i - 1] * 2;
    e5s[i] = e5s[i - 1] * 5;
  }

  int ax, ay, bx, by;
  getpos(ax, ay); getpos(bx, by);

  while (ax != 7 || ay != 9) {
    if (ax < 7) ax++;
    else if (ax > 7) ax--;
    else if (ay < 9) ay++;

    if (getputpos(ax, ay, bx, by)) return 0;
  }

  if (hdist(ax, ay, bx, by) & 1) {
    for (int i = 0; i < 2; i++) {
      ax++;
      if (getputpos(ax, ay, bx, by)) return 0;
    }
  }
  else {
    ax += 2;
    if (getputpos(ax, ay, bx, by)) return 0;
  }

  for (;;) {
    int dx = ax - bx, dy = ay - by;
    if (dx >= dy) ax--;
    else ay--;
    if (getputpos(ax, ay, bx, by)) break;
  }
  return 0;
}

0