結果

問題 No.186 中華風 (Easy)
ユーザー face4face4
提出日時 2019-02-20 11:57:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 962 bytes
コンパイル時間 562 ms
コンパイル使用メモリ 70,820 KB
実行使用メモリ 13,824 KB
最終ジャッジ日時 2024-04-24 03:22:58
合計ジャッジ時間 6,927 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

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

bool comp(pair<ll,ll> a, pair<ll,ll> b){
    if(a.second != b.second)    return a.second > b.second;
    else                        return a.first > b.first;
}

int main(){
    pair<ll, ll> p[3];
    for(int i = 0; i < 3; i++)  cin >> p[i].first >> p[i].second;
    sort(p, p+3, comp);
    bool valid = true;
    for(int i = 1; i < 3; i++){
        for(int j = 0; j < i; j++){
            if(p[i].second%p[j].second) continue;
            valid &= (p[i].first%p[j].second)==p[j].first;
        }
    }
    if(!valid){
        cout << -1 << endl;
        return 0;
    }
    ll ans = p[2].first;
    while(ans%p[1].second != p[1].first)    ans += p[2].second;
    ll g = p[1].second*p[2].second/gcd(p[1].second,p[2].second);
    while(ans%p[0].second != p[0].first)    ans += g;
    cout << ans << endl;
    return 0;
}
0