結果
問題 | No.75 回数の期待値の問題 |
ユーザー | HEXAebmr |
提出日時 | 2021-02-11 08:30:25 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 4,779 bytes |
コンパイル時間 | 3,525 ms |
コンパイル使用メモリ | 196,964 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-17 21:44:30 |
合計ジャッジ時間 | 3,997 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,944 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 1 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 3 ms
6,940 KB |
testcase_18 | AC | 4 ms
6,940 KB |
testcase_19 | AC | 5 ms
6,940 KB |
ソースコード
#include <algorithm> #include <atcoder/all> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdint> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <queue> #include <random> #include <regex> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using vll = vector<ll>; using vvll = vector<vector<ll>>; using vvvll = vector<vector<vector<ll>>>; using vii = vector<int>; using vvii = vector<vector<int>>; using vvvii = vector<vector<vector<int>>>; using vdd = vector<double>; using vvdd = vector<vector<double>>; using vvvdd = vector<vector<vector<double>>>; using vbb = vector<bool>; using vvbb = vector<vector<bool>>; using vvvbb = vector<vector<vector<bool>>>; #define pb push_back #define mp make_pair #define sc second #define fr first #define endl '\n' #define stpr std::fixed << setprecision #define cYES cout << "YES" << endl #define cNO cout << "NO" << endl #define cYes cout << "Yes" << endl #define cNo cout << "No" << endl #define rep(i, n) for (ll i = 0; i < (n); ++i) #define drep(i, a, b, d) for (ll i = (a); i <= (b); i += d) #define Rep(i, a, b) for (ll i = (a); i < (b); ++i) #define rrep(i, n) for (ll i = n - 1; i >= 0; i--) #define drrep(i, a, b, d) for (ll i = (a); i >= (b); i -= d) #define rRep(i, a, b) for (ll i = a; i >= b; i--) #define crep(i) for (char i = 'a'; i <= 'z'; ++i) #define Crep(i) for (char i = 'A'; i <= 'Z'; ++i) #define ALL(x) (x).begin(), (x).end() #define rALL(x) (x).rbegin(), (x).rend() #define sort2(A, N) \ sort(A, A + N, \ [](const pii &a, const pii &b) { return a.second < b.second; }); #define debug(v) \ cout << #v << ":"; \ for (auto x : v) { \ cout << x << ' '; \ } \ cout << endl; int ctoi(const char c) { if ('0' <= c && c <= '9') return (c - '0'); return -1; } ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } constexpr ll MOD = 1000000007; constexpr ll INF = 1000000011; constexpr ll MOD2 = 998244353; constexpr ll LINF = 1001002003004005006ll; constexpr ld EPS = 10e-10; template <class T, class U> inline bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &&x : v) is >> x; return is; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first; is >> p.second; return is; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << ' ' << p.second; return os; } template <class T> ostream &operator<<(ostream &os, vector<T> &v) { for (auto i = begin(v); i != end(v); ++i) { if (i != begin(v)) os << ' '; os << *i; } return os; } // 連立方程式の形をそのまま入れる vdd gauss_jordan(vvdd &A, const vdd &b) { int n_ = A.size(), m_ = A[0].size(); if (n_ < m_) { return vdd(); } vvdd B(n_, vdd(m_ + 1)); auto c = b; for (int i = 0; i < n_; i++) { for (int j = 0; j < m_; j++) { B[i][j] = A[i][j]; } } for (int i = 0; i < n_; i++) { B[i][m_] = b[i]; } for (int i = 0; i < m_; i++) { int pivot = i; for (int j = i; j < n_; j++) { if (abs(B[j][i]) > abs(B[pivot][i])) { pivot = j; } } swap(B[i], B[pivot]); swap(c[i], c[pivot]); if (abs(B[i][i]) < EPS) { return vdd(); } for (int j = i + 1; j <= m_; j++) { B[i][j] /= B[i][i]; } for (int j = 0; j < n_; j++) { if (i != j) { for (int k = i + 1; k <= m_; k++) { B[j][k] -= B[j][i] * B[i][k]; } } } } vdd x(m_); for (int i = 0; i < m_; i++) { x[i] = B[i][m_]; } bool T = 0; for (int i = m_; i < n_; i++) { ld sum = 0; for (int j = 0; j < m_; j++) { sum += x[j] * B[i][j]; } if (sum - c[i] > EPS) { return vdd(); } } return x; } int main() { ll K; cin >> K; vvdd A(K + 1, vdd(K + 1, 0)); vdd B(K + 1, -1.0); rep(i, K) { A[i][i] = -1.0; rep(j, 6) { ll t = i + j + 1; if (t > K) { t = 0; } A[i][t] += 1.0 / 6.0; } } A[K][K] = 1; B[K] = 0; auto V = gauss_jordan(A, B); cout << stpr(15) << V[0] << endl; }