結果

問題 No.176 2種類の切手
ユーザー nakacity_peoplenakacity_people
提出日時 2015-05-31 14:50:24
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 856 bytes
コンパイル時間 585 ms
コンパイル使用メモリ 67,648 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 22:12:30
合計ジャッジ時間 1,571 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 RE -
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int ans = 0x7fffffff;
int sum = 0;
int A, B, T;
void setSum(int _sum) {
	sum = _sum;

	if ( sum < ans && T <= sum ) ans = sum;
}

int main() {
	cin >> A >> B >> T;

	if ( A > B ) swap(A, B);

	long long gcd = __gcd(A, B);
	long long lcm = A * B / gcd;
	if ( T / B > 1000000 ) {
		int m = (T - lcm) / gcd + ( ((T - lcm) % gcd > 0) ? 1 : 0 );
		cout << lcm + m * gcd << endl;
		return 1;
	}

	int count = (T / A) + 1;
	
	setSum( A * count );

	while ( count-- ) {
		int next = sum - A;
		while (next < T) next += B;
		setSum( next );

		if ( sum == T ) break;
	}

	cout << ans << endl;

	return 0;
}
0