結果
問題 | No.959 tree and fire |
ユーザー | homesentinel |
提出日時 | 2019-12-15 00:11:01 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 4,737 bytes |
コンパイル時間 | 991 ms |
コンパイル使用メモリ | 116,968 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-06 14:27:48 |
合計ジャッジ時間 | 2,437 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 1 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 | 1 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 1 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 1 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 1 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 2 ms
5,376 KB |
testcase_32 | AC | 1 ms
5,376 KB |
testcase_33 | AC | 1 ms
5,376 KB |
testcase_34 | AC | 1 ms
5,376 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 1 ms
5,376 KB |
testcase_37 | AC | 2 ms
5,376 KB |
testcase_38 | AC | 2 ms
5,376 KB |
testcase_39 | AC | 1 ms
5,376 KB |
testcase_40 | AC | 2 ms
5,376 KB |
testcase_41 | AC | 1 ms
5,376 KB |
testcase_42 | AC | 1 ms
5,376 KB |
testcase_43 | AC | 1 ms
5,376 KB |
testcase_44 | AC | 2 ms
5,376 KB |
testcase_45 | AC | 1 ms
5,376 KB |
testcase_46 | AC | 1 ms
5,376 KB |
testcase_47 | AC | 2 ms
5,376 KB |
testcase_48 | AC | 1 ms
5,376 KB |
testcase_49 | AC | 1 ms
5,376 KB |
testcase_50 | AC | 2 ms
5,376 KB |
testcase_51 | AC | 1 ms
5,376 KB |
testcase_52 | AC | 1 ms
5,376 KB |
testcase_53 | AC | 1 ms
5,376 KB |
testcase_54 | AC | 2 ms
5,376 KB |
testcase_55 | AC | 1 ms
5,376 KB |
testcase_56 | AC | 2 ms
5,376 KB |
ソースコード
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #include <climits> #include <cstring> #define rep(i, m, n) for(int i=int(m);i<int(n);i++) #define all(c) begin(c),end(c) template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } typedef long long int ll; using ll = long long int; using ull = long long unsigned int; using Int = long long int; using namespace std; #define INF (1 << 30) - 1 #define INFl (ll)5e15 #define DEBUG 0 #define dump(x) cerr << #x << " = " << (x) << endl #define MOD 1000000007 //edit class Solve { public: Int N, M; double p; void init() { cin >> N >> M >> p; } void init(Int N_, Int M_, double p_) { N = N_; M = M_; p = p_; } double solve() { if (N == 1 && M == 1) { cout << p << endl; return p; } if (N > M) swap(N, M); if (N == 1) { double ans = (M - 2) * pow(p, 3) + 2 * pow(p, 2); cout << ans << endl; return ans; } Int cnt_corner = 4; // if (N == 1 && M == 1) cnt_corner = 1; // else if (N == 1 || M == 1) cnt_corner = 2; Int cnt_outer = max(0ll, N - 2) * 2 + max(0ll, M - 2) * 2; Int cnt_inner = N * M - cnt_corner - cnt_outer; double p_corner = pow(p, 3); double p_outer = pow(p, 4); double p_inner = pow(p, 5); double ans = cnt_corner * p_corner + cnt_outer * p_outer + cnt_inner * p_inner; cout << ans << endl; return ans; } }; class Fool { public: Int N, M; double p; void init() { cin >> N >> M >> p; } void init(Int N_, Int M_, double p_) { N = N_; M = M_; p = p_; } double solve() { // モンテカルロ法で解く Int mon = (Int) 1e3; Int total_score = 0; rep(_, 0, mon) { vector<vector<Int>> field(N + 2, vector<Int>(M + 2)); for (int i = 1; i <= N; ++i) { for (int j = 1; j <= M; ++j) { Int R = 1000000; if (rand() % R < R * p) { field[i][j] = 1; } else { field[i][j] = -1; } } } Int score = 0; for (int i = 1; i <= N; ++i) { for (int j = 1; j <= M; ++j) { bool flag = field[i][j] == 1; int di[] = {1, 0, -1, 0}; int dj[] = {0, 1, 0, -1}; for (int k = 0; k < 4; ++k) { if (field[i + di[k]][j + dj[k]] == -1) { flag = false; } } if (flag) score++; } } total_score += score; } double ans = 1. * total_score / mon; cout << ans << endl; return ans; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); // Solve().solve(); bool debug = true; debug = false; if (!debug) { Solve solve; solve.init(); solve.solve(); } else { while (true) { Int MIN_N = 1; Int MAX_N = 100; Int MIN_M = 1; Int MAX_M = 100; Int R = 10000000; Int N = MIN_N + rand() % (MAX_N - MIN_N + 1); Int M = MIN_M + rand() % (MAX_M - MIN_M + 1); double p = 1. * (rand() % R) / R; cout << "Input" << endl; cout << N << " " << M << " " << p << endl; cout << "Output" << endl; Solve solve; solve.init(N, M, p); double sans = solve.solve(); Fool fool; fool.init(N, M, p); double fans = fool.solve(); double sotai = (sans - fans) / fans; if (fabs(sotai) > 1e-1 && abs(sans - fans) > 1e-1) { exit(-1); } } } return 0; }