結果

問題 No.1680 Sum and Difference
コンテスト
ユーザー tktk_snsn
提出日時 2021-09-17 21:42:25
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 25 ms / 1,000 ms
+ 379µs
コード長 408 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 53 ms
コンパイル使用メモリ 14,592 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2026-10-15 21:18:49
合計ジャッジ時間 2,089 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

mod = 10 ** 9 + 7
A, B = map(int, input().split())
if A > B:
    A, B = B, A

if A == 0 and B == 0:
    print(1)
    exit()

if A == 0:
    if B % 2 == 0:
        print((B + 1) % mod)
    else:
        print(B % mod)
    exit()

if (A + B) % 2 == 0:
    b = 2 * (A + 1 + B + 1) - 4
    S = 2 * A * B
    ans = S + 1 + b // 2
    print(ans % mod)
else:
    ans = A * (B + 1) + B * (A + 1)
    print(ans % mod)
0