結果

問題 No.1680 Sum and Difference
ユーザー tonyu0tonyu0
提出日時 2021-09-18 10:47:02
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 933 bytes
コンパイル時間 578 ms
コンパイル使用メモリ 135,516 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-12 20:26:41
合計ジャッジ時間 1,853 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 0 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 WA -
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;
const MOD: i64 = 1000000007;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let mut a: i64 = itr.next().unwrap().parse::<i64>().unwrap();
    let mut b: i64 = itr.next().unwrap().parse::<i64>().unwrap();

    // -A <= x+y <= A
    // -B <= x-y <= B
    // -A-y <= x <= A-y
    // -B+y <= x <= B+y
    // max(-A-y,-B+y) <= x <= min(A-y,B+y)
    // -A-y=-B+y -> y=(-A+B)/2, x=(-A-B)/2 - bottom
    // A-y=B+y -> y=(A-B)/2, x=(A+B)/2 - top
    // -B+y=A-y -> y=(A+B)/2, x=(A-B)/2 - right
    // -A-y=B+y -> y=(-A-B)/2, x=(-A+B)/2 - left
    if a == 0 && b == 0 {
        println!("1");
    } else if a == 0 {
        println!("{}", b);
    } else if b == 0 {
        println!("{}", a);
    } else {
        a %= MOD;
        b %= MOD;
        println!("{}", ((a + 1) * (b + 1) % MOD + a * b % MOD) % MOD);
    }
}
0