提出 #20466423


ソースコード 拡げる

#include <atcoder/all>
using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = 3.14159265359;
const ll INF = 1LL << 60;

vector<double> dp0;
vector<double> dp1;
vector<bool> hole;

int main()
{
  int n, m, k;
  cin >> n >> m >> k;

  dp0.resize(n+1+m);
  dp1.resize(n+1+m);
  hole.resize(n+1);

  for (int i = 0; i < k; i++){
    int ak;
    cin >> ak;
    hole[ak] = true;
  }

  int ct = 0;
  for (int i = 0; i <= n; i++){
    if (hole[i]) ct++;
    else ct = 0;
    if (ct == m){
      cout << -1 << endl;
      return 0;
    }
  }
  
  // X = f(0)
  // g(i) = dp0(i) * X + dp1(i)
  double mm = (double) m;
  double sum0 = 0.0;
  double sum1 = 0.0;
  for (int i = n-1; i >= 0; i--){
    if (hole[i]){
      dp0[i] = 1.0;
      dp1[i] = 0.0;
    } else {
      dp0[i] = sum0 / mm;
      dp1[i] = sum1 / mm + 1.0;
    }
    sum0 += dp0[i] - dp0[i+m];
    sum1 += dp1[i] - dp1[i+m];
  }

  double ans = dp1[0] / (1 - dp0[0]);
  cout << fixed << setprecision(4) << ans << endl;
  return 0;
}

提出情報

提出日時
問題 F - Sugoroku2
ユーザ unnohideyuki
言語 C++ (GCC 9.2.1)
得点 600
コード長 1104 Byte
結果 AC
実行時間 13 ms
メモリ 6456 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 4
AC × 30
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All hand_01.txt, hand_02.txt, hand_04.txt, max_01.txt, max_02.txt, max_03.txt, max_04.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_14.txt, random_15.txt, random_16.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, unreachable_01.txt, unreachable_02.txt, unreachable_03.txt, unreachable_04.txt
ケース名 結果 実行時間 メモリ
hand_01.txt AC 13 ms 4668 KiB
hand_02.txt AC 4 ms 4720 KiB
hand_04.txt AC 2 ms 3752 KiB
max_01.txt AC 5 ms 4816 KiB
max_02.txt AC 5 ms 4872 KiB
max_03.txt AC 6 ms 4720 KiB
max_04.txt AC 6 ms 4868 KiB
random_01.txt AC 6 ms 6456 KiB
random_02.txt AC 4 ms 5132 KiB
random_03.txt AC 4 ms 4696 KiB
random_04.txt AC 2 ms 3748 KiB
random_05.txt AC 8 ms 6304 KiB
random_06.txt AC 7 ms 6348 KiB
random_07.txt AC 6 ms 4868 KiB
random_08.txt AC 2 ms 3768 KiB
random_09.txt AC 6 ms 6252 KiB
random_10.txt AC 5 ms 5248 KiB
random_11.txt AC 9 ms 4764 KiB
random_12.txt AC 5 ms 4700 KiB
random_14.txt AC 5 ms 5844 KiB
random_15.txt AC 6 ms 4868 KiB
random_16.txt AC 4 ms 3980 KiB
sample_01.txt AC 2 ms 3684 KiB
sample_02.txt AC 2 ms 3680 KiB
sample_03.txt AC 2 ms 3568 KiB
sample_04.txt AC 6 ms 4724 KiB
unreachable_01.txt AC 2 ms 3812 KiB
unreachable_02.txt AC 6 ms 3972 KiB
unreachable_03.txt AC 2 ms 3816 KiB
unreachable_04.txt AC 3 ms 4344 KiB