結果
問題 |
No.178 美しいWhitespace (1)
|
ユーザー |
![]() |
提出日時 | 2016-02-27 14:56:08 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 702 bytes |
コンパイル時間 | 478 ms |
コンパイル使用メモリ | 56,960 KB |
実行使用メモリ | 13,760 KB |
最終ジャッジ日時 | 2024-09-24 11:37:37 |
合計ジャッジ時間 | 3,976 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 2 |
other | WA * 1 TLE * 1 -- * 19 |
ソースコード
#include <iostream> 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,n,lcmkeep; cin >> n; int a[n],b[n],space[n]; for(int i = 0;i < n;i++) cin >> a[i] >> b[i]; for(int i = 0;i < n;i++) space[i] = a[i] + 4 * b[i]; for(int i = 0;i < n;i++){ if(i == 0){ lcmkeep = lcm(space[i],space[i + 1]); i += 2; }else lcmkeep = lcm(lcmkeep,space[i]); } for(int i = 0;i < n;i++) ans += lcmkeep - space[i]; cout << ans << endl; }