結果

問題 No.1478 Simple Sugoroku
ユーザー hirono999hirono999
提出日時 2021-04-16 22:02:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 4,982 bytes
コンパイル時間 3,073 ms
コンパイル使用メモリ 222,504 KB
実行使用メモリ 8,960 KB
最終ジャッジ日時 2023-09-16 00:42:25
合計ジャッジ時間 7,208 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 76 ms
8,908 KB
testcase_14 AC 75 ms
8,920 KB
testcase_15 AC 76 ms
8,852 KB
testcase_16 AC 76 ms
8,824 KB
testcase_17 AC 76 ms
8,788 KB
testcase_18 AC 75 ms
8,792 KB
testcase_19 AC 75 ms
8,888 KB
testcase_20 AC 75 ms
8,960 KB
testcase_21 AC 75 ms
8,892 KB
testcase_22 AC 76 ms
8,824 KB
testcase_23 AC 76 ms
8,780 KB
testcase_24 AC 75 ms
8,840 KB
testcase_25 AC 76 ms
8,888 KB
testcase_26 AC 76 ms
8,856 KB
testcase_27 AC 76 ms
8,924 KB
testcase_28 AC 73 ms
8,888 KB
testcase_29 AC 74 ms
8,852 KB
testcase_30 AC 74 ms
8,884 KB
testcase_31 AC 73 ms
8,800 KB
testcase_32 AC 73 ms
8,888 KB
testcase_33 AC 75 ms
8,928 KB
testcase_34 AC 74 ms
8,884 KB
testcase_35 AC 74 ms
8,880 KB
testcase_36 AC 74 ms
8,916 KB
testcase_37 AC 75 ms
8,860 KB
testcase_38 AC 76 ms
8,796 KB
testcase_39 AC 75 ms
8,888 KB
testcase_40 AC 74 ms
8,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "/home/snow/competitive-programming/competitive-programming-library/snow/template.hpp"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

constexpr long long INF = 1LL << 60;
constexpr long double PI = 3.141592653589;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define to_s to_string
#define len(v) (ll) v.size()
#define debug(x) cout << #x << ": " << (x) << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> tpl;

template <typename T = ll>
using vec = vector<T>;

template <typename T = ll>
using vec2 = vector<vector<T>>;

template <typename T = ll>
using vec3 = vector<vector<vector<T>>>;

template < typename T >
inline bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

template < typename T >
inline bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#line 4 "/home/snow/competitive-programming/competitive-programming-library/snow/io/setup.hpp"

namespace snow{

struct IoSetup {
    IoSetup() {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
        std::cout << std::fixed << std::setprecision(10);
    }
} iosetup;

}
#line 5 "/home/snow/competitive-programming/competitive-programming-library/snow/io/helper.hpp"

template< typename T1, typename T2 >
std::ostream &operator << (std::ostream &os, const std::pair< T1, T2 > &p) {
    os << p.first << " " << p.second;
    return os;
}

template< typename T1, typename T2 >
std::istream &operator >> (std::istream &is, std::pair< T1, T2 > &p) {
    is >> p.first >> p.second;
    return is;
}

template< typename T1, typename T2, typename T3 >
std::ostream &operator << (std::ostream &os, const std::tuple< T1, T2, T3 > &t) {
    auto &[a, b, c] = t;
    os << a << " " << b << " " << c;
    return os;
}

template< typename T1, typename T2, typename T3 >
std::istream &operator >> (std::istream &is, std::tuple< T1, T2, T3 > &t) {
    auto &[a, b, c] = t;
    is >> a >> b >> c;
    return is;
}

template< typename T >
std::ostream &operator << (std::ostream &os, const std::vector< T > &v){
    for (int i = 0; i < (int)v.size(); ++i) {
        os << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return os;
}

template< typename T >
std::istream &operator >>  (std::istream &is, std::vector< T > &v){
    for(T &in : v) is >> in;
    return is;
}

template< typename T >
std::ostream &operator << (std::ostream &os, const std::set< T > &st){
    int ct = 0;
    for(auto& s : st) os << s << (++ct != st.size() ? " " : "");
    return os;
}

template<class... T>
void input(T&... a){
    (std::cin >> ... >> a);
}

void print() {
    std::cout << '\n';
}
template<class T, class... Ts>
void print(const T& a, const Ts&... b){
    std::cout << a;
    (std::cout << ... << (std::cout << ' ', b));
    std::cout << '\n';
}

int drop() {
    std::cout << '\n';
    exit(0);
}
template<class T, class... Ts>
int drop(const T& a, const Ts&... b){
    std::cout << a;
    (std::cout << ... << (std::cout << ' ', b));
    std::cout << '\n';
    exit(0);
}
#line 4 "main.cpp"
using namespace snow;

// #include "snow/algorithm/binary-search.hpp"

// #include "atcoder/modint"
// using namespace atcoder;
// using mint = modint1000000007;

#line 2 "/home/snow/competitive-programming/competitive-programming-library/snow/algorithm/binary-search.hpp"

namespace snow {

/**
 * @brief Binary Search
 * @param EPS Sepcify if using decimal floating point
 * @return right
 */
template< typename T, typename F >
T binary_search(T left, T right, F f, T EPS = 1) {
    while(abs(right - left) > EPS){
        T mid = (right + left) / 2;
        if(f(mid)) right = mid;
        else left = mid;
    }
    return right;
}

} // namespace snow
#line 13 "main.cpp"

int main() {
    ll N, M;
    cin >> N >> M;
    vec<> B(M);
    cin >> B;

    ld rem = B[0] - 1 + N - B[M - 1];

    //5.333
    auto bi = [&](ld X)->bool {
        vec<ld> f(M);
        auto dp = [&](auto&& self, ll x)->ld {
            if(x == M - 1) return 0;
            ld d = B[x + 1] - B[x];
            f[x] = min(self(self, x + 1) + d, X + 1);
            return f[x];
        };
        dp(dp, 0);

        ld e = 0;
        rep(i, M) e += f[i];
        e /= M;

        return X > e;
    };

    auto ret = snow::binary_search<ld>(0, 1e10, bi, 1e-8);

    ld X = ret;
    vec<ld> f(M);
    auto dp = [&](auto&& self, ll x)->ld {
        if(x == M - 1) return 0;
        ld d = B[x + 1] - B[x];
        f[x] = min(self(self, x + 1) + d, X + 1);
        return f[x];
    };
    dp(dp, 0);

    print(f[0] + rem);

    return 0;
}
0