結果
| 問題 |
No.1501 酔歩
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2021-05-07 22:09:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,478 bytes |
| コンパイル時間 | 6,174 ms |
| コンパイル使用メモリ | 380,132 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-15 10:05:30 |
| 合計ジャッジ時間 | 13,434 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 RE * 2 |
| other | AC * 3 WA * 13 RE * 37 |
ソースコード
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
boost::multiprecision::cpp_int gcd(boost::multiprecision::cpp_int a, boost::multiprecision::cpp_int b){
if (b == 0){
return a;
} else {
return gcd(b, a % b);
}
}
struct fraction{
boost::multiprecision::cpp_int num, den;
fraction(){
}
fraction(boost::multiprecision::cpp_int a, boost::multiprecision::cpp_int b){
boost::multiprecision::cpp_int 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 {
assert(false);
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 << ans.num << "/" << ans.den << endl;
}
}
SSRS