結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,032 KB
testcase_01 AC 12 ms
5,892 KB
testcase_02 AC 12 ms
5,976 KB
testcase_03 AC 11 ms
5,868 KB
testcase_04 AC 11 ms
5,892 KB
testcase_05 AC 11 ms
6,064 KB
testcase_06 AC 11 ms
6,096 KB
testcase_07 AC 11 ms
5,872 KB
testcase_08 AC 11 ms
5,936 KB
testcase_09 AC 12 ms
5,868 KB
testcase_10 AC 12 ms
5,868 KB
testcase_11 WA -
testcase_12 AC 11 ms
6,100 KB
testcase_13 AC 11 ms
5,872 KB
testcase_14 AC 11 ms
5,952 KB
testcase_15 AC 11 ms
6,012 KB
testcase_16 AC 12 ms
6,096 KB
testcase_17 WA -
testcase_18 AC 12 ms
5,872 KB
testcase_19 AC 12 ms
5,896 KB
testcase_20 AC 12 ms
6,124 KB
testcase_21 WA -
testcase_22 AC 12 ms
6,096 KB
testcase_23 AC 12 ms
6,096 KB
testcase_24 AC 11 ms
5,876 KB
testcase_25 AC 12 ms
5,900 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: x = [(x1,x2)]
elif x2 <= 0: x = [(-x2,-x1)]
else: x = [(1,-x1),(0,x2)]
if y1 >= 0: y = [(y1,y2)]
elif y2 <= 0: y = [(-y2,-y1)]
else: y = [(1,-y1),(0,y2)]
ans = 0
for x1,x2 in x:
	for y1,y2 in y:
		#print (x1,y1),(x2,y2)
		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