結果
問題 |
No.186 中華風 (Easy)
|
ユーザー |
|
提出日時 | 2019-02-20 11:55:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 948 bytes |
コンパイル時間 | 794 ms |
コンパイル使用メモリ | 70,932 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-06 10:08:33 |
合計ジャッジ時間 | 4,668 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | RE * 23 |
コンパイルメッセージ
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 | } | ^
ソースコード
#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; }