結果

問題 No.751 Frac #2
ユーザー YDK1727YDK1727
提出日時 2018-11-09 22:11:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,203 bytes
コンパイル時間 1,733 ms
コンパイル使用メモリ 166,060 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-13 11:35:07
合計ジャッジ時間 2,929 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
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 AC 2 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 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 1 ms
4,380 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h" // {{{
using namespace std;
#define eb          emplace_back
#define emp         emplace
#define fi          first
#define se          second
#define X           first
#define Y           second
#define outl(x)     cout << (x) << '\n'
#define rep(i,n)    for(int i=0; i < (int)(n); ++i)
#define ALL(x)      begin(x), end(x)
#define TMPLT(T,U)  template<class T, class U>
#define ten(p)      (int)(1e##p)
#define FILL(a,val) memset((a), (val), sizeof(a))
#define FAST()      ios::sync_with_stdio(false), cin.tie(nullptr)
#ifdef DEBUG
#define debug(...)  fprintf(stderr, __VA_ARGS__)
#define show(x)     clog << #x << " \t= " << (x) << '\n'
#define line()      fputs("\n--------------------------------\n", stderr)
#else
#define debug(...)
#define show(x)
#define LN()
#endif
using ll  = long long;
using pii = pair<int,int>;
TMPLT(T,U) inline bool chmax(T &a, U b){return b>a ? a=b,1 : 0;}
TMPLT(T,U) inline bool chmin(T &a, U b){return b<a ? a=b,1 : 0;}
TMPLT(T,U) inline constexpr common_type_t<T,U> gcd(T x, U y) { return (x<y)? gcd(y,x) : (y <= 0)? x : gcd(y, x % y); }
TMPLT(T,U) inline constexpr ll lcm(T x, U y) { return (ll)x/gcd(x,y) * y; }
inline bool inner(int val, int min, int max){ return min <= val && val < max; }
constexpr int INF   = 0x3f3f3f3f;
constexpr ll LINF   = 0x3f3f3f3f3f3f3f3fLL;

namespace ydk{ // }}}

constexpr int MXN = ten(5) + 10;


signed _vim_is_god_()
{
    int N, A, B;
    int tmp;
    pii a, b;

    cin >> N >> tmp;
    a = pii(tmp, 1);
    rep(i, N-1) {
        int x; cin >> x;
        a.se *= x;
    }

    cin >> N >> tmp;
    b = pii(tmp, 1);
    rep(i, N-1) {
        int x; cin >> x;
        b.se *= x;
    }

    debug("a: %d %d\n", a.fi, a.se);
    debug("b: %d %d\n", b.fi, b.se);

    pii ans = pii(a.fi * b.se,   a.se * b.fi);
    int g = gcd(ans.fi, ans.se);
    ans.fi /= g;
    ans.se /= g;

    if (ans.fi * ans.se < 0) {
        ans.fi = -1 * abs(ans.fi);
        ans.se = abs(ans.se);
    }

    if (ans.se != 1) {
        cout << ans.fi << ' ' << ans.se << endl;
    } else {
        outl(ans.fi);
    }
    return 0;
}

} // {{{

signed main(){cout << fixed << setprecision(9); ydk::_vim_is_god_(); return 0;} // }}}

0