結果

問題 No.1448 和差算
コンテスト
ユーザー lloyz
提出日時 2022-05-12 21:28:10
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 725 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 406 ms
コンパイル使用メモリ 20,828 KB
実行使用メモリ 36,024 KB
最終ジャッジ日時 2026-04-03 01:07:47
合計ジャッジ時間 5,194 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys

if len(sys.argv) == 2:
    sys.stdin = open(sys.argv[1])

a, b, c, d = map(int, input().split())
n = int(input())
mod = 10**9 + 7

q, r = divmod(n, 8)
ans = -10**18
for x in [a, b]:
    for y in [c, d]:
        if r == 0:
            ans = max(ans, x + y)
        elif r == 1:
            ans = max(ans, 2 * x)
        elif r == 2:
            ans = max(ans, 2 * (x - y))
        elif r == 3:
            ans = max(ans, -4 * y)
        elif r == 4:
            ans = max(ans, -4 * (x + y))
        elif r == 5:
            ans = max(ans, -8 * x)
        elif r == 6:
            ans = max(ans, -8 * (x - y))
        else:
            ans = max(ans, 16 * y)
ans %= mod
ans *= pow(16, q, mod)
ans %= mod
print(ans)
0