結果

問題 No.751 Frac #2
ユーザー sahiyasahiya
提出日時 2020-12-08 11:41:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,623 bytes
コンパイル時間 1,538 ms
コンパイル使用メモリ 112,248 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 17:04:01
合計ジャッジ時間 2,834 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef bitset<16> BS;

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 10;

int N1, N2;

ll A[MAX_N + 1], B[MAX_N + 1];

ll gcd(ll a, ll b);

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N1;
    bool sgn = true;
    for (int i = 1; i <= N1; i++) {
        cin >> A[i];
        if (A[i] < 0)
            sgn = !sgn;
    }
    cin >> N2;
    for (int i = 1; i <= N2; i++) {
        cin >> B[i];
        if (B[i] < 0)
            sgn = !sgn;
    }

    ll p_a = 1, p_b = 1;
    for (int i = 2; i <= N1; i++) {
        p_a *= A[i];
    }
    for (int i = 2; i <= N2; i++) {
        p_b *= B[i];
    }

    ll d = gcd(abs(A[1] * p_b), abs(B[1] * p_a));

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */
    ll a = abs(A[1] * p_b) / d;
    ll b = abs(B[1] * p_a) / d;
    if (!sgn)
        a *= -1;

    cout << a << " " << b << "\n";

    return 0;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;

    return gcd(b, a % b);
}
0