結果

問題 No.1501 酔歩
ユーザー SSRSSSRS
提出日時 2021-05-07 22:12:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,574 bytes
コンパイル時間 6,020 ms
コンパイル使用メモリ 408,064 KB
実行使用メモリ 10,144 KB
最終ジャッジ日時 2023-10-13 13:22:28
合計ジャッジ時間 12,185 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 96 ms
8,280 KB
testcase_06 AC 75 ms
7,132 KB
testcase_07 AC 93 ms
8,120 KB
testcase_08 AC 23 ms
4,352 KB
testcase_09 AC 81 ms
7,592 KB
testcase_10 AC 33 ms
5,208 KB
testcase_11 AC 72 ms
7,008 KB
testcase_12 AC 52 ms
6,024 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 124 ms
10,108 KB
testcase_23 AC 123 ms
9,968 KB
testcase_24 AC 121 ms
9,976 KB
testcase_25 AC 125 ms
9,784 KB
testcase_26 AC 123 ms
9,948 KB
testcase_27 AC 125 ms
9,816 KB
testcase_28 AC 122 ms
9,848 KB
testcase_29 AC 124 ms
9,812 KB
testcase_30 AC 124 ms
9,792 KB
testcase_31 AC 124 ms
9,944 KB
testcase_32 AC 127 ms
9,928 KB
testcase_33 AC 125 ms
9,948 KB
testcase_34 AC 121 ms
9,792 KB
testcase_35 AC 123 ms
9,888 KB
testcase_36 AC 123 ms
9,904 KB
testcase_37 AC 122 ms
10,144 KB
testcase_38 AC 124 ms
9,940 KB
testcase_39 AC 127 ms
9,864 KB
testcase_40 AC 121 ms
9,880 KB
testcase_41 AC 129 ms
9,848 KB
testcase_42 AC 95 ms
10,096 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 92 ms
9,840 KB
testcase_46 AC 93 ms
9,816 KB
testcase_47 AC 93 ms
9,916 KB
testcase_48 AC 104 ms
9,884 KB
testcase_49 AC 103 ms
9,760 KB
testcase_50 AC 104 ms
9,840 KB
testcase_51 AC 110 ms
9,740 KB
testcase_52 AC 104 ms
9,844 KB
testcase_53 WA -
testcase_54 AC 2 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];
  }
  assert(1 <= K && K <= N && N <= 100000);
  for (int i = 0; i < N; i++){
    assert(1 <= A[i] && A[i] <= 10);
  }
  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