結果

問題 No.1501 酔歩
ユーザー nok0
提出日時 2021-04-08 20:40:48
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,241 bytes
コンパイル時間 896 ms
コンパイル使用メモリ 60,528 KB
最終ジャッジ日時 2025-01-20 13:09:17
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:39:10: fatal error: testlib.h: No such file or directory
   39 | #include "testlib.h"
      |          ^~~~~~~~~~~
compilation terminated.

ソースコード

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