結果

問題 No.1478 Simple Sugoroku
ユーザー simansiman
提出日時 2022-02-10 01:16:17
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,072 bytes
コンパイル時間 1,171 ms
コンパイル使用メモリ 105,212 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-07 11:50:40
合計ジャッジ時間 3,781 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 42 ms
4,376 KB
testcase_14 AC 40 ms
4,380 KB
testcase_15 AC 42 ms
4,380 KB
testcase_16 AC 42 ms
4,376 KB
testcase_17 AC 41 ms
4,376 KB
testcase_18 AC 42 ms
4,376 KB
testcase_19 AC 42 ms
4,376 KB
testcase_20 AC 42 ms
4,376 KB
testcase_21 AC 42 ms
4,376 KB
testcase_22 AC 42 ms
4,380 KB
testcase_23 AC 42 ms
4,380 KB
testcase_24 AC 42 ms
4,380 KB
testcase_25 AC 42 ms
4,376 KB
testcase_26 AC 42 ms
4,380 KB
testcase_27 AC 42 ms
4,380 KB
testcase_28 AC 44 ms
4,380 KB
testcase_29 AC 38 ms
4,376 KB
testcase_30 AC 38 ms
4,380 KB
testcase_31 AC 38 ms
4,380 KB
testcase_32 AC 37 ms
4,380 KB
testcase_33 AC 37 ms
4,380 KB
testcase_34 AC 37 ms
4,380 KB
testcase_35 AC 37 ms
4,380 KB
testcase_36 AC 39 ms
4,376 KB
testcase_37 AC 39 ms
4,376 KB
testcase_38 AC 39 ms
4,376 KB
testcase_39 AC 39 ms
4,376 KB
testcase_40 AC 40 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int N, M;
vector<int> B;

double f(int mid) {
  if (mid < 0) return INT_MAX;
  if (M <= mid) return INT_MAX;

  int len = M - mid;
  double val = 0.0;

  for (int i = M - 1; i >= mid; --i) {
    int b = B[i];
    double cnt = (B[0] - 1) + M * 1.0 / len + (N - b);
    val += cnt;
  }

  return val / len;
}

int main() {
  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int b;
    cin >> b;
    B.push_back(b);
  }

  int l = 0;
  int r = M - 1;

  for (int i = 0; i < 10000; ++i) {
    int i_1 = (l * 2 + r) / 3;
    int i_2 = (l + r * 2) / 3;

    if (f(i_1) < f(i_2)) {
      r = i_1;
    } else {
      l = i_2;
    }
  }

  int mid = (l + r) / 2;
  double ans = N - 1.0;
  for (int i = mid - 1000; i <= mid + 1000; ++i) {
    ans = min(ans, f(i));
  }
  cout << fixed << setprecision(10) << ans << endl;

  return 0;
}
0