結果

問題 No.1501 酔歩
コンテスト
ユーザー nok0
提出日時 2021-04-08 19:55:48
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 25 ms / 2,000 ms
+ 442µs
コード長 1,087 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,303 ms
コンパイル使用メモリ 215,248 KB
実行使用メモリ 9,928 KB
最終ジャッジ日時 2026-10-21 22:59:17
合計ジャッジ時間 4,657 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

struct rational {
public:
	rational() = default;
	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/(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;
	}
};

int n, k;
int a[100000];
int main() {
	std::cin >> n >> k;
	for(int i = 0; i < n; i++) std::cin >> a[i];

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

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