結果

問題 No.750 Frac #1
ユーザー FF256grhyFF256grhy
提出日時 2018-11-09 21:22:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,838 bytes
コンパイル時間 1,870 ms
コンパイル使用メモリ 169,064 KB
実行使用メモリ 4,512 KB
最終ジャッジ日時 2023-08-13 11:01:19
合計ジャッジ時間 3,026 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

struct Frac {
	LL p, q;
	Frac() { };
	Frac(LL pp, LL qq = 1) {
		if(qq < 0) { pp *= -1; qq *= -1; }
		LL d = gcd(abs(pp), qq);
		p = pp / d; q = qq / d;
	}
	bool operator< (const Frac & obj) const { return p * obj.q <  obj.p * q; }
	bool operator> (const Frac & obj) const { return p * obj.q >  obj.p * q; }
	bool operator<=(const Frac & obj) const { return p * obj.q <= obj.p * q; }
	bool operator>=(const Frac & obj) const { return p * obj.q >= obj.p * q; }
	bool operator==(const Frac & obj) const { return p * obj.q == obj.p * q; }
	bool operator!=(const Frac & obj) const { return p * obj.q != obj.p * q; }
	Frac operator+ (const Frac & obj) const { return Frac(p * obj.q + obj.p * q, q * obj.q); }
	Frac operator- (const Frac & obj) const { return Frac(p * obj.q - obj.p * q, q * obj.q); }
	Frac operator* (const Frac & obj) const { return Frac(p * obj.p, q * obj.q); }
	Frac operator/ (const Frac & obj) const { return Frac(p * obj.q, q * obj.p); }
};
ostream & operator<<(ostream & os, const Frac & f) {
	if(f.q == 1) { os << f.p; } else { os << f.p << "/" << f.q; }
	return os;
}

int n;
Frac x[10];

int main() {
	cin >> n;
	inc(i, n) {
		int a, b;
		cin >> a >> b;
		x[i] = Frac(a, b);
	}
	sort(x, x + n);
	reverse(x, x + n);
	
	inc(i, n) {
		cout << x[i].p << " " << x[i].q << endl;
	}
	
	return 0;
}
0