結果

問題 No.1352 Three Coins
ユーザー tkmst201tkmst201
提出日時 2021-01-26 17:04:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 2,020 bytes
コンパイル時間 2,091 ms
コンパイル使用メモリ 200,460 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 20:48:42
合計ジャッジ時間 4,704 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 6 ms
4,376 KB
testcase_03 AC 13 ms
4,376 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 32 ms
4,380 KB
testcase_06 AC 40 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 50 ms
4,376 KB
testcase_09 AC 11 ms
4,376 KB
testcase_10 AC 30 ms
4,376 KB
testcase_11 AC 21 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 12 ms
4,376 KB
testcase_14 AC 41 ms
4,380 KB
testcase_15 AC 10 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 14 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 66 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 40 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 77 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 70 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

/*
まず、gcd(A, B, C) != 1 の場合は gcd 倍の値しか表現できないため `INF`
xA + yB + zC で表現可能な数を調べる

y >= A の場合、x を B 増やし y を A 減らしても式の値は同じため、y は mod A での値 0 <= y < A のみ考えれば良い
z についても同様に 0 <= z < A とする。

yB + zC で表現可能な値以上で mod A で等しい値はすべて表現可能であることに注意すると、
yB + zC が取りうる値で mod A の値が 0 から A-1 まですべて取りうるなら AB + AC 以上の値は全て表現可能である。

拡張ユークリッドの互除法より、ある x', y' が存在して、x' B + y' C = gcd(B, C) =: g である
今、gcd(A, B, C) = gcd(g, C) = 1 であるので、f(x) = gx (mod. A) は全射から yB + zC が mod A で 0 から A-1 まですべて取りうることが言えた。
*/

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (gcd(A, gcd(B, C)) > 1) { puts("INF"); return 0; }
	
	vector<bool> exist(A * (B + C), false);
	exist[0] = true;
	REP(i, exist.size()) {
		if (!exist[i]) continue;
		if (i + A < exist.size()) exist[i + A] = true;
		if (i + B < exist.size()) exist[i + B] = true;
		if (i + C < exist.size()) exist[i + C] = true;
	}
	
	int ans = 0;
	REP(i, exist.size()) ans += !exist[i];
	cout << ans << endl;
}
0