結果

問題 No.751 Frac #2
ユーザー gazellegazelle
提出日時 2018-11-09 22:23:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,359 bytes
コンパイル時間 1,402 ms
コンパイル使用メモリ 106,444 KB
実行使用メモリ 4,512 KB
最終ジャッジ日時 2023-08-13 11:43:08
合計ジャッジ時間 2,938 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

ll gcd(ll a, ll b) {		// ユークリッドの互除法
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n1;
	cin >> n1;
	vector<ll> a(n1);
	REP(i,n1) cin >> a[i];
	if(n1 == 1) {
		n1++;
		a.pb(a[0]);
		a[0] = 1;
	}
	ll n2;
	cin >> n2;
	vector<ll> b(n2);
	REP(i,n2) cin >> b[i];
	if(n2 == 1) {
		n2++;
		b.pb(1);
	}
	reverse(ALL(a));
	while(n1 > 2) {
		a[n1 - 3] = a[n1 - 3] * a[n1 - 2];
		a[n1 - 2] = a[n1 - 1];
		n1--;
	}
	while(n2 > 2) {
		b[n2 - 3] = b[n2 - 3] * b[n2 - 1];
		n2--;
	}
	ll up = a[1] * b[1], dw = a[0] * b[0];
	if(dw < 0 && up < 0) {
		dw = abs(dw);
		up = abs(up);
	} else if (dw < 0) {
		dw = abs(dw);
		up = -up;
	}
	ll g = gcd(up, dw);
	cout << up / g << " " << dw / g << endl;
	return 0;
}
0