結果
| 問題 |
No.178 美しいWhitespace (1)
|
| コンテスト | |
| ユーザー |
ldsyb
|
| 提出日時 | 2016-02-27 15:42:51 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 739 bytes |
| コンパイル時間 | 568 ms |
| コンパイル使用メモリ | 59,580 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-24 11:39:32 |
| 合計ジャッジ時間 | 1,363 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 2 |
| other | AC * 6 WA * 15 |
ソースコード
#include <iostream>
#include <cmath>
using namespace std;
int gcd(int x,int y){
if((x == 0) || (y == 0)) return 0;
while(x != y){
if(x > y) x -= y;
else y -= x;
}
return x;
}
int lcm(int x,int y){
if((x == 0) || (y == 0)) return 0;
return (x * y / gcd(x,y));
}
int main(){
int ans = 0,lenmax = 0,n;
bool oe;
cin >> n;
int a[n],b[n],length[n];
for(int i = 0;i < n;i++){
cin >> a[i] >> b[i];
length[i] = a[i] + 4 * b[i];
if(!i) oe = length[i] % 2;
if(oe != length[i] % 2){
cout << -1 << endl;
return 0;
}
lenmax = max(lenmax,lcm(lenmax,length[i]));
}
for(int i = 0;i < n;i++) ans += lenmax - length[i];
cout << ans / 2 << endl;
}
ldsyb