結果

問題 No.751 Frac #2
ユーザー Y17Y17
提出日時 2018-11-09 22:09:10
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,082 bytes
コンパイル時間 1,206 ms
コンパイル使用メモリ 145,272 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-13 11:33:52
合計ジャッジ時間 2,665 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 WA -
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
  long long n1, n2;
  long long a;
  pair<long long, long long> bun1, bun2 , ans;

  cin >> n1 >> a;

  bun1.first = a;
  bun1.second = 1;

  int cnt = 0;

  for(long long i = 1;i < n1;i++){
    cin >> a;
    if(a < 0) cnt++;
    bun1.second *= abs(a);
    long long tmp = __gcd(bun1.first, bun1.second);
    bun1.first /= tmp;
    bun1.second /= tmp;
  }



  cin >> n2;

  long long b[20];
  for(long long i = 0;i < n2;i++){
    cin >> b[i];
    if(b[i] < 0) cnt++;
    b[i] = abs(b[i]);
  }

  bun2.first = b[n2-1];
  bun2.second = 1;

  for(long long i = n2-2;i >= 0;i--){
    long long x = bun2.first;
    long long y = bun2.second;

    bun2.first = b[i] * y;
    bun2.second = x;

    long long tmp = __gcd(bun2.first, bun2.second);
    bun2.first /= tmp;
    bun2.second /= tmp;
  }

  ans.first = bun1.first * bun2.second;
  ans.second = bun1.second * bun2.first;

  long long tmp = __gcd(ans.first, ans.second);

  if(cnt % 2) cout << '-';
  cout << ans.first/tmp << " " << ans.second/tmp << endl;

  return 0;
}
0