結果

問題 No.176 2種類の切手
ユーザー nikollson
提出日時 2015-04-28 18:55:34
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 875 bytes
コンパイル時間 520 ms
コンパイル使用メモリ 66,776 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-08 03:20:16
合計ジャッジ時間 1,590 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)
#define pb push_back

using namespace std;


const int T = 1000;
const int INF = 1111111111;
int visit[T];

int main(){
	
	int a,b,t;
	cin>>a>>b>>t;
	
	
	if(b<a)swap(a,b);
	
	int m = min(a,b);
	
	rep(i,T)visit[i] = 0;
	
	int ans = INF;
	if(m<T){
		int anum = (t+(a-1))/a;
		int bnum = 0;
		while(1){
			int A = anum*a;
			int B = bnum*b;
			
			int val = A+B;
			ans = min(ans, val);
			if(visit[val-t]==1)break;
			visit[val-t]=1;
			
			bnum++;
			anum = ((t-bnum*b)+(a-1))/a;
			
			if(t-bnum*b<0)break;
		}
	}else{
		for(int i=0;;i++){
			int c = a*i;
			int r = (max(0, t-c)+(b-1))/b;
			ans = min(ans, c+r*b);
			if(c>=t)break;
		}
	}
	
	printf("%d\n",ans);
}
0