結果

問題 No.959 tree and fire
ユーザー face4face4
提出日時 2019-12-22 09:14:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 920 bytes
コンパイル時間 818 ms
コンパイル使用メモリ 71,148 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-13 21:00:24
合計ジャッジ時間 2,396 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 54
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
using namespace std;

int di[8] = {0,0,1,-1,1,1,-1,-1};
int dj[8] = {1,-1,0,0,1,-1,1,-1};
#define inRange(x,a,b) (a <= x && x < b)

int main(){
    double n, m, p;
    cin >> n >> m >> p;
    double d;
    if(n == 1 && m == 1){
        d = p;
    }else if(n == 1 || m == 1){
        double x = max(n, m);
        d = p*p*min(2.0, x) + p*p*p*max(0.0,x-2);
    }else if(n >= 2 && m >= 2){
        d = p*p*p*4+p*p*p*p*2*(n-2+m-2)+p*p*p*p*p*(n-2)*(m-2);
    }else{
        d = 0;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                double r = p;
                for(int k = 0; k < 4; k++){
                    int ni = i+di[k], nj = j+dj[k];
                    if(inRange(ni,0,n)&&inRange(nj,0,m))  r *= p;
                }
                d += r;
            }
        }
    }
    cout << fixed << setprecision(12) << d << endl;
    return 0;
}
0