結果

問題 No.751 Frac #2
ユーザー どららどらら
提出日時 2018-11-09 22:28:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,406 bytes
コンパイル時間 1,734 ms
コンパイル使用メモリ 169,308 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-13 11:47:00
合計ジャッジ時間 3,032 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b){return (b==0?a:gcd(b,a%b));}



pair<ll,ll> solve(const vector<ll>& v, const vector<ll>& w){
  if(v.size()==0){
    return make_pair(1LL,1LL);
  }
  if(v.size()==1){
    ll g = gcd(v[0], w[0]);
    return make_pair(v[0]/g,w[0]/g);
  }

  ll x = v[v.size()-1] * w[0];
  
  vector<ll> vv, ww;
  rep(i,v.size()-2) vv.push_back(v[i]);
  vv[0] *= w[1];
  REP(i,2,w.size()) ww.push_back(w[i]);
  ww[0] *= v[v.size()-2];

  pair<ll,ll> ret = solve(vv, ww);
  ret.second *= x;
  ll g = gcd(ret.first, ret.second);  
  return make_pair(ret.first/g, ret.second/g);
}


int main(){
  int n, m;
  vector<ll> v, w;
  cin >> n;
  rep(i,n){
    ll a;
    cin >> a;
    v.push_back(a);
  }
  cin >> m;
  rep(i,m){
    ll a;
    cin >> a;
    w.push_back(a);
  }

  if(n<11) rep(i,11-n) v.push_back(1);
  if(m<11) rep(i,11-m) w.push_back(1);

  pair<ll,ll> ret = solve(v,w);
  if(ret.first < 0 && ret.second < 0){
    ret.first *= -1;
    ret.second *= -1;
  }
  else if(ret.second < 0){
    ret.first *= -1;
    ret.second *= -1;
  }
  cout << ret.first << " " << ret.second << endl;
  
  return 0;
}

0