結果

問題 No.1501 酔歩
ユーザー SSRSSSRS
提出日時 2021-05-07 22:01:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,157 bytes
コンパイル時間 1,415 ms
コンパイル使用メモリ 167,820 KB
実行使用メモリ 5,164 KB
最終ジャッジ日時 2023-10-13 13:04:38
合計ジャッジ時間 5,484 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 WA -
testcase_05 AC 58 ms
4,604 KB
testcase_06 AC 46 ms
4,376 KB
testcase_07 AC 60 ms
4,372 KB
testcase_08 AC 15 ms
4,348 KB
testcase_09 AC 49 ms
4,452 KB
testcase_10 AC 21 ms
4,352 KB
testcase_11 AC 44 ms
4,352 KB
testcase_12 AC 31 ms
4,352 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 76 ms
4,848 KB
testcase_23 AC 74 ms
4,852 KB
testcase_24 AC 71 ms
4,908 KB
testcase_25 AC 75 ms
4,824 KB
testcase_26 AC 76 ms
4,916 KB
testcase_27 AC 78 ms
4,960 KB
testcase_28 AC 73 ms
4,856 KB
testcase_29 AC 79 ms
4,980 KB
testcase_30 AC 75 ms
4,824 KB
testcase_31 AC 78 ms
4,980 KB
testcase_32 AC 79 ms
4,920 KB
testcase_33 AC 79 ms
4,824 KB
testcase_34 AC 72 ms
4,860 KB
testcase_35 AC 76 ms
5,164 KB
testcase_36 AC 73 ms
4,824 KB
testcase_37 AC 74 ms
4,856 KB
testcase_38 AC 78 ms
4,916 KB
testcase_39 AC 80 ms
4,820 KB
testcase_40 AC 71 ms
4,852 KB
testcase_41 WA -
testcase_42 AC 29 ms
4,972 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 27 ms
4,916 KB
testcase_46 AC 27 ms
4,820 KB
testcase_47 AC 26 ms
4,916 KB
testcase_48 AC 38 ms
4,856 KB
testcase_49 AC 38 ms
4,856 KB
testcase_50 AC 38 ms
4,900 KB
testcase_51 AC 48 ms
4,908 KB
testcase_52 AC 37 ms
5,024 KB
testcase_53 WA -
testcase_54 AC 1 ms
4,356 KB
testcase_55 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
  }
}
0