結果
問題 |
No.1501 酔歩
|
ユーザー |
![]() |
提出日時 | 2021-05-07 22:03:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,285 bytes |
コンパイル時間 | 1,805 ms |
コンパイル使用メモリ | 171,212 KB |
実行使用メモリ | 6,912 KB |
最終ジャッジ日時 | 2024-09-15 09:56:35 |
合計ジャッジ時間 | 6,361 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 WA * 13 |
ソースコード
#include <bits/stdc++.h> using namespace std; __int128 gcd(__int128 a, __int128 b){ if (b == 0){ return a; } else { return gcd(b, a % b); } } struct fraction{ __int128 num, den; fraction(){ } fraction(__int128 a, __int128 b){ __int128 g = gcd(a, b); num = a / g; den = b / g; } fraction operator +(fraction x){ return fraction(num * x.den + x.num * den, den * x.den); } fraction operator -(fraction x){ return fraction(num * x.den - x.num * den, den * x.den); } fraction operator *(fraction x){ return fraction(num * x.num, den * x.den); } fraction operator /(fraction x){ return fraction(num * x.den, den * x.num); } }; int main(){ int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } K--; if (K == 0){ cout << "0" << endl; } else if (K == N - 1){ cout << "1/1" << endl; } else { vector<fraction> dp(N); dp[0] = fraction(0, 1); dp[1] = fraction(1, 1); for (int i = 2; i < N; i++){ dp[i] = fraction(A[i - 2] + A[i], A[i]) * dp[i - 1] - fraction(A[i - 2], A[i]) * dp[i - 2]; } fraction x = fraction(1, 1) / dp[N - 1]; fraction ans = x * dp[K]; cout << (long long) ans.num << "/" << (long long) ans.den << endl; } }