結果

問題 No.1680 Sum and Difference
ユーザー kiyoshiro944kiyoshiro944
提出日時 2021-09-30 19:04:21
言語 Go
(1.22.1)
結果
TLE  
実行時間 -
コード長 721 bytes
コンパイル時間 10,935 ms
コンパイル使用メモリ 211,684 KB
実行使用メモリ 7,904 KB
最終ジャッジ日時 2023-09-24 23:04:15
合計ジャッジ時間 13,549 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	// -A ≤ x + y ≤ A
	// -B ≤ x - y ≤ B
	// ---------------
	// - (A+B) ≤ 2x ≤ A+B
	// - (A+B) / 2 ≤ x ≤ (A+B)/2

	// -A ≤ x + y ≤ A
	// -B ≤ y - x ≤ B
	// ---------------
	// - (A+B) ≤ 2y ≤ A+B
	// - (A+B) / 2 ≤ y ≤ (A+B)/2
	// したがって、xとyの範囲が求まる
	var to int
	to = (a + b) / 2

	result := 0
	for x := 0; x <= to; x++ {
		for y := 0; y <= to; y++ {
			if -a <= x+y && x+y <= a && -b <= x-y && x-y <= b {
				// fmt.Println(x, y)
				result += 1
			}
		}
	}

	// 反転したもの(x2)、0, 0が重複するのを考慮する(-1)
	ans := (result*2 - 1) % 1000000007
	fmt.Println(ans)
}
0