結果

問題 No.1501 酔歩
ユーザー nok0nok0
提出日時 2021-04-08 20:40:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,241 bytes
コンパイル時間 6,939 ms
コンパイル使用メモリ 307,160 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 12:00:37
合計ジャッジ時間 11,976 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 26 ms
4,348 KB
testcase_06 AC 21 ms
4,348 KB
testcase_07 AC 24 ms
4,348 KB
testcase_08 AC 8 ms
4,348 KB
testcase_09 AC 21 ms
4,348 KB
testcase_10 AC 11 ms
4,348 KB
testcase_11 AC 17 ms
4,352 KB
testcase_12 AC 18 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,352 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 35 ms
4,348 KB
testcase_23 AC 32 ms
4,348 KB
testcase_24 AC 34 ms
4,348 KB
testcase_25 AC 37 ms
4,348 KB
testcase_26 AC 41 ms
4,352 KB
testcase_27 AC 36 ms
4,348 KB
testcase_28 AC 30 ms
4,348 KB
testcase_29 AC 40 ms
4,352 KB
testcase_30 AC 26 ms
4,348 KB
testcase_31 AC 40 ms
4,348 KB
testcase_32 AC 39 ms
4,352 KB
testcase_33 AC 32 ms
4,348 KB
testcase_34 AC 34 ms
4,348 KB
testcase_35 AC 37 ms
4,352 KB
testcase_36 AC 33 ms
4,352 KB
testcase_37 AC 41 ms
4,348 KB
testcase_38 AC 39 ms
4,352 KB
testcase_39 AC 28 ms
4,348 KB
testcase_40 AC 38 ms
4,348 KB
testcase_41 AC 32 ms
4,348 KB
testcase_42 AC 28 ms
4,348 KB
testcase_43 AC 2 ms
4,352 KB
testcase_44 AC 1 ms
4,352 KB
testcase_45 AC 20 ms
4,348 KB
testcase_46 AC 18 ms
4,352 KB
testcase_47 AC 24 ms
4,348 KB
testcase_48 AC 29 ms
4,348 KB
testcase_49 AC 24 ms
4,352 KB
testcase_50 AC 30 ms
4,352 KB
testcase_51 AC 30 ms
4,352 KB
testcase_52 AC 30 ms
4,352 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 2 ms
4,352 KB
testcase_55 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

struct rational {
public:
	rational(long long x, long long y) : x(x), y(y) {}

	rational& operator+=(const rational oth) {
		auto& [z, w] = oth;
		auto ny = y / std::gcd(y, w) * w;
		auto nx = ny / y * x + ny / w * z;
		x = nx, y = ny;
		reduction();
		return *this;
	}
	rational& operator/=(const rational oth) {
		auto& [z, w] = oth;
		x *= w, y *= z;
		reduction();
		return *this;
	}
	rational operator/(const rational oth) { return rational(*this) /= oth; }

	friend std::ostream& operator<<(std::ostream& s, rational a) {
		if(a.x == 0 and a.y == 1)
			s << '0';
		else
			s << a.x << '/' << a.y;
		return s;
	}

private:
	long long x, y;
	void reduction() {
		long long g = std::gcd(x, y);
		x /= g, y /= g;
	}
};

#include "testlib.h"
int n, k;
int a[100000];
int main() {
	registerValidation();
	n = inf.readInt(1, 100000);
	inf.readSpace();
	k = inf.readInt(1, n);
	inf.readEoln();
	for(int i = 0; i < n; i++) {
		if(i) inf.readSpace();
		a[i] = inf.readInt(1, 10);
	}
	inf.readEoln();
	inf.readEof();

	auto f = [&](int x) {
		rational res(0, 1);
		for(int i = 0; i < x; i++)
			res += rational(1, a[i] * a[i + 1]);
		return res;
	};

	std::cout << (n != 1 ? f(--k) / f(--n) : rational(1, 1)) << '\n';
}
0