結果
| 問題 | 
                            No.959 tree and fire
                             | 
                    
| コンテスト | |
| ユーザー | 
                             homesentinel
                         | 
                    
| 提出日時 | 2019-12-17 18:03:22 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 1,566 bytes | 
| コンパイル時間 | 895 ms | 
| コンパイル使用メモリ | 114,264 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-06 14:27:59 | 
| 合計ジャッジ時間 | 2,218 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 54 | 
ソースコード
#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>
#include <cassert>
using namespace std;
using Int = long long int;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    Int N, M;
    double P;
    cin >> N >> M >> P;
    assert(1 <= N && N <= 1000000000);
    assert(1 <= M && M <= 1000000000);
    assert(0.0 <= P && P <= 1.0);
    if (N == 1 && M == 1) {
        cout << P << endl;
        return 0;
    }
    if (N > M) swap(N, M);
    if (N == 1) {
        double ans = (M - 2) * pow(P, 3) + 2 * pow(P, 2);
        cout << ans << endl;
        return 0;
    }
    Int cnt_corner = 4;
    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 0;
}
            
            
            
        
            
homesentinel