結果

問題 No.959 tree and fire
ユーザー rogi52
提出日時 2022-10-03 23:51:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 791 bytes
コンパイル時間 2,047 ms
コンパイル使用メモリ 194,008 KB
最終ジャッジ日時 2025-02-07 21:03:42
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 54
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    

    using ld = long double;
    ld N,M,P; cin >> N >> M >> P;
    if(N > M) swap(N, M);
    ld ans = 0;
    if(M == 1) {
        ans += P;
    } else if(N == 1) {
        // k = 1 : 2マス
        // k = 2 : M-2マス
        ans += 2.0 * powl(P, 1 + 1);
        ans += (M - 2) * powl(P, 2 + 1);
    } else {
        // k = 2 : 4マス
        // k = 3 : 2(N-2+M-2)マス
        // k = 4 : (N-1)(M-1)マス
        ans += 4.0 * powl(P, 2 + 1);
        ans += 2.0 * (N - 2 + M - 2) * powl(P, 3 + 1);
        ans += (N - 2) * (M - 2) * powl(P, 4 + 1);
    }
    cout << fixed << setprecision(20) << ans << endl;
}
0