結果
| 問題 |
No.1478 Simple Sugoroku
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-17 11:33:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 79 ms / 2,000 ms |
| コード長 | 2,140 bytes |
| コンパイル時間 | 3,927 ms |
| コンパイル使用メモリ | 251,220 KB |
| 最終ジャッジ日時 | 2025-01-20 21:01:13 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:86:12: warning: 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];
| ^
In file included from /usr/include/c++/13/vector:66,
from /usr/include/c++/13/functional:64,
from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53,
from main.cpp:1:
/usr/include/c++/13/bits/stl_vector.h:1126:7: note: declared here
1126 | operator[](size_type __n) _GLIBCXX_NOEXCEPT
| ^~~~~~~~
ソースコード
#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;
}