結果

問題 No.1152 10億ゲーム
ユーザー nikkukunnikkukun
提出日時 2020-08-14 01:39:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 2,128 bytes
コンパイル時間 1,474 ms
コンパイル使用メモリ 166,876 KB
実行使用メモリ 24,360 KB
平均クエリ数 22.98
最終ジャッジ日時 2023-09-24 05:33:25
合計ジャッジ時間 8,274 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
23,532 KB
testcase_01 AC 71 ms
23,976 KB
testcase_02 AC 74 ms
23,964 KB
testcase_03 AC 76 ms
23,484 KB
testcase_04 AC 73 ms
23,592 KB
testcase_05 AC 75 ms
24,024 KB
testcase_06 AC 74 ms
23,964 KB
testcase_07 AC 75 ms
24,060 KB
testcase_08 AC 74 ms
24,348 KB
testcase_09 AC 71 ms
23,328 KB
testcase_10 AC 72 ms
23,976 KB
testcase_11 AC 74 ms
23,664 KB
testcase_12 AC 75 ms
24,072 KB
testcase_13 AC 71 ms
24,012 KB
testcase_14 AC 75 ms
23,328 KB
testcase_15 AC 73 ms
23,532 KB
testcase_16 AC 72 ms
24,336 KB
testcase_17 AC 75 ms
24,048 KB
testcase_18 AC 74 ms
24,036 KB
testcase_19 AC 75 ms
23,616 KB
testcase_20 AC 73 ms
24,324 KB
testcase_21 AC 73 ms
24,336 KB
testcase_22 AC 72 ms
23,592 KB
testcase_23 AC 72 ms
23,328 KB
testcase_24 AC 76 ms
24,348 KB
testcase_25 AC 74 ms
24,336 KB
testcase_26 AC 75 ms
24,288 KB
testcase_27 AC 74 ms
23,376 KB
testcase_28 AC 74 ms
23,976 KB
testcase_29 AC 74 ms
24,360 KB
testcase_30 AC 76 ms
23,532 KB
testcase_31 AC 77 ms
23,424 KB
testcase_32 AC 77 ms
24,288 KB
testcase_33 AC 73 ms
23,520 KB
testcase_34 AC 73 ms
24,324 KB
testcase_35 AC 74 ms
23,544 KB
testcase_36 AC 75 ms
24,324 KB
testcase_37 AC 75 ms
23,988 KB
testcase_38 AC 72 ms
24,012 KB
testcase_39 AC 74 ms
23,640 KB
testcase_40 AC 73 ms
23,580 KB
testcase_41 AC 73 ms
23,832 KB
testcase_42 AC 76 ms
23,772 KB
testcase_43 AC 74 ms
24,348 KB
testcase_44 AC 75 ms
23,592 KB
testcase_45 AC 76 ms
24,024 KB
testcase_46 AC 74 ms
24,000 KB
testcase_47 AC 75 ms
23,988 KB
testcase_48 AC 75 ms
24,336 KB
testcase_49 AC 74 ms
23,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int N = 100 + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;
const int dx[] = {-1, 0, 1, 0, 2};
const int dy[] = {0, 1, 0, -1, 0};

int vst[N][N][2];
int f[N][N][2], nxt[N][N][2]; // 0: first, 1: second

bool OK(int x, int y) {
	return x >= 0 && x <= 9 && y >= 0 && y <= 9;
}

void BFS() {
	memset(f, 0x3f, sizeof(f));
	memset(nxt, -1, sizeof(nxt));

	for (int i = 0; i < 100; i++)
		for (int op = 0; op <= 1; op++)
			f[i][i][op] = 0;

	for (int t = 1; t < 100; t++) {
		for (int op = 0; op <= 1; op++)
			for (int u = 0; u < 100; u++)
				for (int v = 0; v < 100; v++) {
					if (f[u][v][op] != INF) continue;

					int minf = INF, minid = -1;
					int maxf = -INF, maxid = -1;
					for (int d = 0; d < 5; d++) {
						int nx = u / 10 + dx[d];
						int ny = u % 10 + dy[d];
						if (!OK(nx, ny)) continue;
						// special judge 79 -> 99
						if (d == 4 && u != 79) continue;

						int nu = nx * 10 + ny;
						int tmpf = f[v][nu][op ^ 1];
						if (tmpf < minf) minf = tmpf, minid = nu;
						if (tmpf > maxf) maxf = tmpf, maxid = nu;
					}

					if (op == 0 && minf != INF) {
						f[u][v][op] = minf + 1;
						nxt[u][v][op] = minid;
					}
					if (op == 1 && maxf != -INF && maxf != INF) {
						f[u][v][op] = maxf + 1;
						nxt[u][v][op] = maxid;
					}
				}
	}
}

int GetPow(int x, int d) {
	int ret = 0;
	while (x % d == 0) {
		ret++;
		x /= d;
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(0);

	BFS();

	int u, v;
	cin >> u >> v;
	int ux = GetPow(u, 2), uy = GetPow(u, 5);
	int vx = GetPow(v, 2), vy = GetPow(v, 5);
	u = ux * 10 + uy;
	v = vx * 10 + vy;

	while (u != v) {
		u = nxt[u][v][0];
		cout << int(pow(2, u / 10) * pow(5, u % 10)) << endl;
		cout << flush;
		if (u == v) break;
		cin >> v;
		vx = GetPow(v, 2), vy = GetPow(v, 5);
		v = vx * 10 + vy;
	}

	return 0;
}
0