結果

問題 No.186 中華風 (Easy)
ユーザー face4face4
提出日時 2019-02-20 11:55:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 948 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 70,112 KB
実行使用メモリ 818,304 KB
最終ジャッジ日時 2024-04-24 03:20:06
合計ジャッジ時間 3,774 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'bool comp(std::pair<long long int, long long int>, std::pair<long long int, long long int>)':
main.cpp:13:1: warning: no return statement in function returning non-void [-Wreturn-type]
   13 | }
      | ^

ソースコード

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)    a.second > b.second;
    else                        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