結果
| 問題 |
No.325 マンハッタン距離2
|
| コンテスト | |
| ユーザー |
tjake
|
| 提出日時 | 2015-12-18 02:48:39 |
| 言語 | Python2 (2.7.18) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 1,000 ms |
| コード長 | 1,055 bytes |
| コンパイル時間 | 335 ms |
| コンパイル使用メモリ | 6,912 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-16 08:23:27 |
| 合計ジャッジ時間 | 1,472 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
x1,y1,x2,y2,d=map(int,raw_input().split())
x1 = max(x1,-d)
x2 = min(x2, d)
y1 = max(y1,-d)
y2 = min(y2, d)
def get(x):
if x == 0:
return [-d, d]
if x == d or x == -d:
return [0]
if x>0:
return [] if x>d else [d-x, x-d]
else:
return [] if x<-d else [d+x, -x-d]
def h(x, y):
return abs(x)+abs(y)
def fix(x, y):
return min(max(x, x1), x2), min(max(y, y1), y2)
p = []
e = get(x1)
p.extend(fix(x1, y) for y in e)
e = get(x2)
p.extend(fix(x2, y) for y in e)
e = get(y1)
p.extend(fix(x, y1) for x in e)
e = get(y2)
p.extend(fix(x, y2) for x in e)
p = list(set(p))
p = [e for e in p if h(e[0], e[1])<=d]
if len(p)==0:
print 0
exit(0)
x1 = min(e[0] for e in p)
x2 = max(e[0] for e in p)
y1 = min(e[1] for e in p)
y2 = max(e[1] for e in p)
ans = (x2-x1+1)*(y2-y1+1)
l = len(p)
for i in xrange(l):
s1, t1 = p[i]
for j in xrange(i+1, l):
s2, t2 = p[j]
dx = abs(s2-s1)
dy = abs(t2-t1)
if dx==dy and h(s1+s2, t1+t2)==2*d:
ans -= dx*(dx+1)/2
print ans
tjake