結果

問題 No.1501 酔歩
ユーザー SSRSSSRS
提出日時 2021-05-07 22:13:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 1,457 bytes
コンパイル時間 6,499 ms
コンパイル使用メモリ 406,588 KB
実行使用メモリ 10,104 KB
最終ジャッジ日時 2023-10-13 13:24:41
合計ジャッジ時間 13,239 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 95 ms
8,276 KB
testcase_06 AC 74 ms
6,960 KB
testcase_07 AC 95 ms
8,016 KB
testcase_08 AC 24 ms
4,352 KB
testcase_09 AC 80 ms
7,548 KB
testcase_10 AC 34 ms
4,716 KB
testcase_11 AC 71 ms
6,952 KB
testcase_12 AC 52 ms
5,908 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 123 ms
9,928 KB
testcase_23 AC 123 ms
9,972 KB
testcase_24 AC 121 ms
9,868 KB
testcase_25 AC 125 ms
10,104 KB
testcase_26 AC 124 ms
9,820 KB
testcase_27 AC 125 ms
9,976 KB
testcase_28 AC 122 ms
9,844 KB
testcase_29 AC 125 ms
9,904 KB
testcase_30 AC 126 ms
9,788 KB
testcase_31 AC 125 ms
9,868 KB
testcase_32 AC 125 ms
9,924 KB
testcase_33 AC 124 ms
9,816 KB
testcase_34 AC 121 ms
9,860 KB
testcase_35 AC 123 ms
9,864 KB
testcase_36 AC 123 ms
9,864 KB
testcase_37 AC 121 ms
9,780 KB
testcase_38 AC 125 ms
9,864 KB
testcase_39 AC 127 ms
10,076 KB
testcase_40 AC 120 ms
9,856 KB
testcase_41 AC 128 ms
9,844 KB
testcase_42 AC 95 ms
9,816 KB
testcase_43 AC 1 ms
4,352 KB
testcase_44 AC 1 ms
4,348 KB
testcase_45 AC 92 ms
9,972 KB
testcase_46 AC 93 ms
10,076 KB
testcase_47 AC 93 ms
9,860 KB
testcase_48 AC 104 ms
9,820 KB
testcase_49 AC 104 ms
9,820 KB
testcase_50 AC 104 ms
9,804 KB
testcase_51 AC 109 ms
9,816 KB
testcase_52 AC 103 ms
10,100 KB
testcase_53 AC 1 ms
4,352 KB
testcase_54 AC 1 ms
4,348 KB
testcase_55 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 == N - 1){
    cout << "1/1" << endl;
  } else if (K == 0){
    cout << 0 << 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