結果
問題 | No.505 カードの数式2 |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:11:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 40 ms / 2,000 ms |
コード長 | 1,288 bytes |
コンパイル時間 | 140 ms |
コンパイル使用メモリ | 82,360 KB |
実行使用メモリ | 54,168 KB |
最終ジャッジ日時 | 2025-03-20 21:12:20 |
合計ジャッジ時間 | 2,430 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
def compute_op(a, b, op):if op == '+':return a + belif op == '-':return a - belif op == '*':return a * belif op == '/':if b == 0:return None# Compute division with truncation towards zeroq = a // b# If the signs are different and there's a remainder, adjust the quotientif (a ^ b) < 0 and a % b != 0:q += 1return qelse:return Nonedef main():import sysinput = sys.stdin.read().split()N = int(input[0])a = list(map(int, input[1:N+1]))if N == 0:print(0)returncurrent_max = a[0]current_min = a[0]for i in range(N-1):next_num = a[i+1]candidates = []for op in ['+', '-', '*', '/']:if op == '/' and next_num == 0:continuefor val in [current_max, current_min]:res = compute_op(val, next_num, op)if res is not None:candidates.append(res)if not candidates:print(0)returncurrent_max = max(candidates)current_min = min(candidates)print(current_max)if __name__ == '__main__':main()