結果

問題 No.1478 Simple Sugoroku
ユーザー shun2741shun2741
提出日時 2021-04-17 11:33:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 2,140 bytes
コンパイル時間 4,227 ms
コンパイル使用メモリ 260,312 KB
実行使用メモリ 4,948 KB
最終ジャッジ日時 2023-09-16 18:49:48
合計ジャッジ時間 8,068 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,436 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 4 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 4 ms
4,468 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 4 ms
4,432 KB
testcase_10 AC 4 ms
4,452 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 63 ms
4,664 KB
testcase_14 AC 62 ms
4,672 KB
testcase_15 AC 63 ms
4,728 KB
testcase_16 AC 64 ms
4,652 KB
testcase_17 AC 63 ms
4,604 KB
testcase_18 AC 64 ms
4,604 KB
testcase_19 AC 65 ms
4,604 KB
testcase_20 AC 64 ms
4,608 KB
testcase_21 AC 62 ms
4,608 KB
testcase_22 AC 64 ms
4,732 KB
testcase_23 AC 63 ms
4,656 KB
testcase_24 AC 62 ms
4,592 KB
testcase_25 AC 65 ms
4,648 KB
testcase_26 AC 65 ms
4,664 KB
testcase_27 AC 61 ms
4,668 KB
testcase_28 AC 53 ms
4,700 KB
testcase_29 AC 55 ms
4,668 KB
testcase_30 AC 57 ms
4,612 KB
testcase_31 AC 55 ms
4,948 KB
testcase_32 AC 55 ms
4,740 KB
testcase_33 AC 57 ms
4,696 KB
testcase_34 AC 58 ms
4,724 KB
testcase_35 AC 57 ms
4,728 KB
testcase_36 AC 59 ms
4,596 KB
testcase_37 AC 61 ms
4,612 KB
testcase_38 AC 59 ms
4,744 KB
testcase_39 AC 60 ms
4,592 KB
testcase_40 AC 60 ms
4,912 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:86:12: 警告: ignoring return value of ‘std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = long long int; _Alloc = std::allocator<long long int>; reference = long long int&; size_type = long unsigned int]’, declared with attribute ‘nodiscard’ [-Wunused-result]
   86 |         B[i];
      |            ^
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/vector:64,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/functional:62,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:71,
         次から読み込み:  main.cpp:1:
/usr/local/gcc7/include/c++/12.2.0/bits/stl_vector.h:1121:7: 備考: ここで宣言されています
 1121 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

// デバッグ表示
#define dump(x) cout << #x << ":" << (x) << endl;

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// modint
using mint = modint1000000007;
// using mint = modint998244353;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第2引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// コンビネーションを計算する関数
ll pow(ll N, ll k) {
    ll res = 1;
    for (ll i = 0; i < k; ++i) res *= N;
    return res;
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

ll N, M;
vector<ll> B;
double dp[100005];

bool check(double X){
    
    Fill(dp, 0);
    dp[M-1] = 0.0;

    // dpテーブル埋め
    for(ll i=M-2; i>=0; i--){
        dp[i] = min(dp[i+1] + double(B[i+1]-B[i]), X + double(1));
    }

    double avg = 0;
    REP(i, M) avg += dp[i];
    avg /= M;

    if(X < avg) return true;
    else return false;

}
int main()
{
    cout << fixed << setprecision(15);
    cin >> N >> M;

    B.resize(M);

    REP(i, M){
        cin >> B[i];
        B[i];
    }

    double left = 0;
    double right = 1e9;
    while(right-left > 0.0000001) { // ループ継続条件
        double middle = ((right - left) / 2) + left;
        //大丈夫なときはもう少し大きい値を見る
        if(check(middle)){ // 範囲右寄せ,左寄せ条件
            left = middle; // 左寄せ手法
        } else {
            right = middle; // 右寄せ手法
        }
    }
    // check(left);
    // dump(dp[0]);

    cout << dp[0] + double((B[0]-1) + (N-B[M-1])) << endl;
    return 0;
}
0