結果

問題 No.1352 Three Coins
ユーザー chocoruskchocorusk
提出日時 2021-01-17 15:54:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,548 bytes
コンパイル時間 1,454 ms
コンパイル使用メモリ 132,220 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 23:06:54
合計ジャッジ時間 2,554 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int a, b, c; cin>>a>>b>>c;
    if(gcd(gcd(a, b), c)>1){
        cout<<"INF"<<endl;
        return 0;
    }
    if(c<a) swap(c, a);
    if(c<b) swap(c, b);
    const int INF=1e9+7;
    int d[2020];
    fill(d, d+c, INF);
    d[0]=0;
    deque<int> deq;
    deq.push_back(0);
    while(!deq.empty()){
        int x=deq[0]; deq.pop_front();
        if(x+a>=c){
            if(d[x+a-c]>d[x]+1){
                deq.push_back(x+a-c);
                d[x+a-c]=d[x]+1;
            }
        }else{
            if(d[x+a]>d[x]){
                deq.push_front(x+a);
                d[x+a]=d[x];
            }
        }
        if(x+b>=c){
            if(d[x+b-c]>d[x]+1){
                deq.push_back(x+b-c);
                d[x+b-c]=d[x]+1;
            }
        }else{
            if(d[x+b]>d[x]){
                deq.push_front(x+b);
                d[x+b]=d[x];
            }
        }
    }
    int ans=0;
    for(int i=0; i<c; i++){
        ans+=d[i];
    }
    cout<<ans<<endl;
    return 0;
}
0