結果

問題 No.751 Frac #2
ユーザー tsutajtsutaj
提出日時 2019-03-29 21:16:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,206 bytes
コンパイル時間 861 ms
コンパイル使用メモリ 105,632 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 16:44:48
合計ジャッジ時間 1,910 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

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

pair<int, int> make_fraction(vector<int> &vec, int l, int r, int mode) {
    if(l == r) return make_pair(1, 1);
    int A = 1, B = 1;

    int nl = -1, nr = -1;
    if(mode == 1) {
        nl = l, nr = r - 1;
        B *= vec[r-1];
    }
    if(mode == 2) {
        nl = l+1, nr = r;
        A *= vec[l];
    }

    int la, lb; tie(la, lb) = make_fraction(vec, nl, nr, mode);
    if(mode == 1) {
        A *= la, B *= lb;
    }
    else {
        A *= lb, B *= la;
    }
    return make_pair(A, B);
}

signed main() {
    int N, M;
    int cntN = 0;
    vector<int> vec1, vec2;
    
    cin >> N;
    for(int i=0; i<N; i++) {
        int val; cin >> val;
        cntN += (val < 0);
        val = abs(val);
        vec1.push_back(val);
    }
    cin >> M;
    for(int i=0; i<M; i++) {
        int val; cin >> val;
        cntN += (val < 0);
        val = abs(val);
        vec2.push_back(val);
    }

    auto fa = make_fraction(vec1, 0, N, 1);
    auto fb = make_fraction(vec2, 0, M, 2);

    int A = 1, B = 1;
    A = fa.first * fb.second;
    B = fa.second * fb.first;
    int g = gcd(A, B);
    A /= g, B /= g;
    if(cntN % 2) A *= -1;
    printf("%lld %lld\n", A, B);
    return 0;
}
0