結果
問題 |
No.959 tree and fire
|
ユーザー |
|
提出日時 | 2019-12-22 16:29:05 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 924 bytes |
コンパイル時間 | 177 ms |
コンパイル使用メモリ | 7,040 KB |
実行使用メモリ | 8,064 KB |
最終ジャッジ日時 | 2024-09-14 08:53:46 |
合計ジャッジ時間 | 2,921 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 54 |
ソースコード
#!/usr/bin/python2 # -*- coding: utf-8 -*- # † from decimal import Decimal from fractions import Fraction as frac def f(N, M, p): if N > M: N, M = M, N s = [0] * 5 if N == 1: if M > 1: s[1] = 2 s[2] = M-2 else: s[2] = 4 s[3] = 2 * (N-2 + M-2) s[4] = (N-2) * (M-2) res = N*M * p for i in [1, 2, 3, 4]: res -= s[i] * (1 - p**i) * p return res def conv(fra): a, b = fra.numerator, fra.denominator integer, rem = divmod(a, b) v = [] while True: if rem == 0: break rem *= 10 quo, rem = divmod(rem, b) v.append(quo) res = '{}.{}'.format(integer, ''.join(map(str, v))) res = res.rstrip('0') if res.endswith('.'): res = res[:-1] return res N, M = map(int, raw_input().split()) p = frac(Decimal(raw_input())) res = f(N, M, p) print conv(res)