結果
問題 | No.463 魔法使いのすごろく🎲 |
ユーザー | omochana2 |
提出日時 | 2019-04-08 00:55:53 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 3,839 bytes |
コンパイル時間 | 1,481 ms |
コンパイル使用メモリ | 168,164 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 10:05:48 |
合計ジャッジ時間 | 2,614 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 3 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 3 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 3 ms
5,376 KB |
testcase_22 | AC | 2 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 3 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 3 ms
5,376 KB |
testcase_32 | AC | 3 ms
5,376 KB |
testcase_33 | AC | 3 ms
5,376 KB |
testcase_34 | AC | 3 ms
5,376 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | AC | 2 ms
5,376 KB |
testcase_38 | AC | 2 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> #define ADD(a, b) a = (a + ll(b)) % mod #define MUL(a, b) a = (a * ll(b)) % mod #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define rep(i, a, b) for(int i = int(a); i < int(b); i++) #define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--) #define all(a) (a).begin(), (a).end() #define sz(v) (int)(v).size() #define pb push_back #define sec second #define fst first #define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<int, pi> ppi; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> mat; typedef complex<double> comp; void Debug() {cout << '\n'; } template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){ cout<<arg<<" ";Debug(rest...);} template<class T>ostream& operator<<(ostream& out,const vector<T>& v) { out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;} template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){ out<<"("<<v.first<<", "<<v.second<<")";return out;} const int MAX_N = 300010; const int MAX_V = 100010; const double eps = 1e-20; const ll mod = 1000000007; const int inf = 1 << 30; const ll linf = 1LL << 60; const double PI = 3.14159265358979323846; /////////////////////////////////////////////////////////////////////////////////////////////////// int get_rank(vector<vi>& B) { //bit vectors, S x S + 1 dimentions int S = sz(B); int r = 0; vector<int> used(S, 0); rep(i, 0, S) { int pivot = -1; rep(j, 0, S) { if(B[j][i] & !used[j]) pivot = j; } if(pivot == -1) continue; r++; swap(B[i], B[pivot]); used[i] = true; rep(j, 0, S) { if(i != j && B[j][i]) { rep(k, 0, S + 1) B[j][k] ^= B[i][k]; } } } return r; } vector<double> gauss_jordan(const vector<vector<double>>& A, const vector<double>& b) { //watch out for precision!!!!!!! int n = sz(A); vector<vector<double>> B(n, vector<double>(n + 1)); rep(i, 0, n) rep(j, 0, n) B[i][j] = A[i][j]; rep(i, 0, n) B[i][n] = b[i]; rep(i, 0, n) { int pivot = i; rep(j, i, n) { if(abs(B[j][i]) > abs(B[pivot][i])) pivot = j; } swap(B[i], B[pivot]); if(abs(B[i][i]) < eps) return vector<double>(); rep(j, i + 1, n + 1) B[i][j] /= B[i][i]; rep(j, 0, n) { if(i != j) { rep(k, i + 1, n + 1) B[j][k] -= B[j][i] * B[i][k]; } } } vector<double> x(n); rep(i, 0, n) x[i] = B[i][n]; return x; } ///////////////////////////////////////////////////////////////// int N, M; double C[MAX_N]; double dp[MAX_N]; void solve() { cin >> N >> M; rep(i, 1, N - 1) cin >> C[i]; vector<vector<double>> A(N, vector<double>(N, 0.0)); vector<double> b(N, 0.0); rep(i, 0, N - 1) { A[i][i] = 1.0; rep(j, 1, M + 1) { if(i + j != N - 1) { int nex = i + j < N - 1 ? i + j : 2 * N - 2 - (i + j); // debug(i, nex); b[i] += 1.0 / M * C[nex]; A[i][nex] -= 1.0 / M; } } } A[N - 1][N - 1] = 1; b = gauss_jordan(A, b); // debug(b); rer(i, N - 1, 0) { if(i + M >= N - 1) dp[i] = 0; else { double tmp = 0; rep(j, 1, M + 1) { int nex = i + j < N - 1 ? i + j : 2 * N - 2 - (i + j); tmp += 1.0 / M * (dp[nex] + C[nex]); } dp[i] = tmp; rep(j, 1, M + 1) { int nex = i + j < N - 1 ? i + j : 2 * N - 2 - (i + j); MIN(dp[i], b[nex] + C[nex]); } } } cout << dp[0] << "\n"; } int main() { #ifndef LOCAL ios::sync_with_stdio(false); cin.tie(0); #endif cout << fixed; cout.precision(20); srand((unsigned int)time(NULL)); #ifdef LOCAL //freopen("in.txt", "wt", stdout); //for tester freopen("in.txt", "rt", stdin); #endif solve(); #ifdef LOCAL cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }