結果
| 問題 |
No.186 中華風 (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-02-20 11:57:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 962 bytes |
| コンパイル時間 | 626 ms |
| コンパイル使用メモリ | 70,268 KB |
| 実行使用メモリ | 16,832 KB |
| 最終ジャッジ日時 | 2024-11-06 10:11:28 |
| 合計ジャッジ時間 | 7,052 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 22 |
ソースコード
#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;
}