結果
問題 | No.463 魔法使いのすごろく🎲 |
ユーザー | omochana2 |
提出日時 | 2019-04-08 00:45:23 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,649 bytes |
コンパイル時間 | 1,500 ms |
コンパイル使用メモリ | 169,816 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-28 09:46:20 |
合計ジャッジ時間 | 2,740 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 3 ms
6,940 KB |
testcase_03 | AC | 3 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 3 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 3 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 3 ms
6,940 KB |
testcase_15 | AC | 3 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 3 ms
6,944 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | WA | - |
testcase_21 | AC | 3 ms
6,944 KB |
testcase_22 | AC | 3 ms
6,940 KB |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | AC | 3 ms
6,944 KB |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 3 ms
6,940 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | AC | 2 ms
6,944 KB |
testcase_36 | AC | 2 ms
6,940 KB |
testcase_37 | AC | 2 ms
6,940 KB |
testcase_38 | AC | 2 ms
6,940 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) { A[i][i] = 1.0; rep(j, 1, M + 1) { if(i + j != N - 1) { b[i] += 1.0 / M * C[(i + j) % N]; A[i][(i + j) % N] -= 1.0 / M; } } } 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) { tmp += 1.0 / M * (dp[i + j] + C[i + j]); } dp[i] = min(tmp, b[i]); rep(j, 1, M + 1) { MIN(dp[i], b[i + j] + C[i + j]); } } } 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; }