結果
問題 |
No.959 tree and fire
|
ユーザー |
![]() |
提出日時 | 2025-03-20 21:06:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 109 ms / 2,000 ms |
コード長 | 1,236 bytes |
コンパイル時間 | 137 ms |
コンパイル使用メモリ | 82,348 KB |
実行使用メモリ | 80,760 KB |
最終ジャッジ日時 | 2025-03-20 21:06:20 |
合計ジャッジ時間 | 7,561 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 54 |
ソースコード
from decimal import Decimal, getcontext getcontext().prec = 30 # Set sufficient precision for calculations n, m = map(int, input().split()) p_str = input().strip() p = Decimal(p_str) # Calculate the number of rows for each possible a (adjacent up/down count) def calculate_rows(n): cnt = [0] * 3 if n == 1: cnt[0] = 1 else: cnt[0] = 0 if n >= 2: cnt[1] = 2 else: cnt[1] = 0 cnt[2] = max(n - 2, 0) if n >= 3 else 0 return cnt # Calculate the number of columns for each possible b (adjacent left/right count) def calculate_cols(m): cnt = [0] * 3 if m == 1: cnt[0] = 1 else: cnt[0] = 0 if m >= 2: cnt[1] = 2 else: cnt[1] = 0 cnt[2] = max(m - 2, 0) if m >= 3 else 0 return cnt cnt_rows = calculate_rows(n) cnt_cols = calculate_cols(m) result = Decimal(0) for a in range(3): for b in range(3): current_count = cnt_rows[a] * cnt_cols[b] if current_count == 0: continue exponent = a + b + 1 term = (current_count) * (p ** exponent) result += term # Ensure output has exactly 10 decimal places formatted_result = format(result, '.10f') print(formatted_result)