結果
| 問題 |
No.1501 酔歩
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2021-05-07 22:01:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,157 bytes |
| コンパイル時間 | 1,777 ms |
| コンパイル使用メモリ | 170,064 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-15 09:54:29 |
| 合計ジャッジ時間 | 6,069 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 39 WA * 14 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct fraction{
long long num, den;
fraction(){
}
fraction(long long a, long long b){
long long 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 << ans.num << "/" << ans.den << endl;
}
}
SSRS