結果

問題 No.1680 Sum and Difference
ユーザー tonyu0tonyu0
提出日時 2021-09-18 11:01:59
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 1,071 bytes
コンパイル時間 630 ms
コンパイル使用メモリ 138,680 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 20:41:17
合計ジャッジ時間 1,538 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 0 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 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 {
        let mut sub = 0;
        if (a & 1) ^ (b & 1) == 1 {
            sub = 1;
        }
        a %= MOD;
        b %= MOD;
        println!(
            "{}",
            (MOD + (a + 1) * (b + 1) % MOD + a * b % MOD - sub) % MOD
        );
    }
}
0