結果

問題 No.325 マンハッタン距離2
ユーザー TawaraTawara
提出日時 2015-12-18 10:14:21
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 729 bytes
コンパイル時間 737 ms
コンパイル使用メモリ 6,680 KB
実行使用メモリ 6,136 KB
最終ジャッジ日時 2023-10-14 13:50:28
合計ジャッジ時間 1,913 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
5,880 KB
testcase_01 AC 9 ms
5,880 KB
testcase_02 AC 10 ms
5,848 KB
testcase_03 AC 9 ms
5,976 KB
testcase_04 AC 9 ms
5,880 KB
testcase_05 AC 9 ms
6,028 KB
testcase_06 AC 8 ms
5,924 KB
testcase_07 AC 9 ms
5,844 KB
testcase_08 AC 9 ms
5,848 KB
testcase_09 AC 9 ms
6,116 KB
testcase_10 AC 10 ms
5,956 KB
testcase_11 WA -
testcase_12 AC 10 ms
5,924 KB
testcase_13 AC 9 ms
6,124 KB
testcase_14 AC 10 ms
5,956 KB
testcase_15 AC 9 ms
5,920 KB
testcase_16 AC 10 ms
6,028 KB
testcase_17 WA -
testcase_18 AC 9 ms
6,136 KB
testcase_19 AC 9 ms
5,904 KB
testcase_20 AC 9 ms
5,900 KB
testcase_21 WA -
testcase_22 AC 9 ms
5,960 KB
testcase_23 AC 10 ms
6,124 KB
testcase_24 AC 10 ms
5,988 KB
testcase_25 AC 9 ms
6,088 KB
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

accum = lambda n: n*(n+1)/2
x1,y1,x2,y2,d = map(int,raw_input().split())
if x1 < 0 < x2: x = [(1,-x1),(0,x2)]
elif x2 <= 0: x = [(-x2,-x1)]
else: x = [(x1,x2)]
if y1 < 0 < y2: y = [(1,-y1),(0,y2)]
elif y2 <= 0: y = [(-y2,-y1)]
else: y = [(y1,y2)]
ans = 0
for x1,x2 in x:
	for y1,y2 in y:
		if x1 + y1 > d: continue
		if x2 + y2 <= d: ans += (x2-x1+1)*(y2-y1+1); continue
		if x2 + y1 >= d:
			bx = d - y1
			if x1 + y2 >= d: 
				ans += accum(bx-x1+1)
			else:
				ux = d - y2; delta = y2-y1+1
				ans += accum(delta) + delta * (ux-x1)
		else:
			ry = d - x2
			if x1 + y2 >= d: 
				delta = x2-x1+1
				ans += accum(delta) + delta * (ry-y1)
			else:
				ux = d - y2
				ans += (x2-x1+1)*(y2-y1+1) - (x2 - ux)*(y2 - ry)
print ans
0