結果

問題 No.178 美しいWhitespace (1)
ユーザー ldsybldsyb
提出日時 2016-02-27 14:56:08
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 702 bytes
コンパイル時間 415 ms
コンパイル使用メモリ 56,888 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 18:33:19
合計ジャッジ時間 4,091 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 TLE -
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 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0