結果

問題 No.325 マンハッタン距離2
ユーザー ayame_pyayame_py
提出日時 2016-01-04 00:25:44
言語 Python2
(2.7.18)
結果
AC  
実行時間 12 ms / 1,000 ms
コード長 871 bytes
コンパイル時間 55 ms
コンパイル使用メモリ 7,132 KB
実行使用メモリ 6,440 KB
最終ジャッジ日時 2023-10-19 14:56:08
合計ジャッジ時間 1,298 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,440 KB
testcase_01 AC 11 ms
6,440 KB
testcase_02 AC 12 ms
6,440 KB
testcase_03 AC 12 ms
6,440 KB
testcase_04 AC 11 ms
6,440 KB
testcase_05 AC 11 ms
6,440 KB
testcase_06 AC 11 ms
6,440 KB
testcase_07 AC 11 ms
6,440 KB
testcase_08 AC 11 ms
6,440 KB
testcase_09 AC 12 ms
6,440 KB
testcase_10 AC 11 ms
6,440 KB
testcase_11 AC 11 ms
6,440 KB
testcase_12 AC 11 ms
6,440 KB
testcase_13 AC 11 ms
6,440 KB
testcase_14 AC 11 ms
6,440 KB
testcase_15 AC 11 ms
6,440 KB
testcase_16 AC 11 ms
6,440 KB
testcase_17 AC 11 ms
6,440 KB
testcase_18 AC 11 ms
6,440 KB
testcase_19 AC 12 ms
6,440 KB
testcase_20 AC 11 ms
6,440 KB
testcase_21 AC 11 ms
6,440 KB
testcase_22 AC 11 ms
6,440 KB
testcase_23 AC 12 ms
6,440 KB
testcase_24 AC 11 ms
6,440 KB
testcase_25 AC 11 ms
6,440 KB
testcase_26 AC 12 ms
6,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def sumn(n): return n*(n+1)/2
x1,y1,x2,y2,d=map(int,raw_input().split())
if x1>=0: xx=[[x1,x2]]
elif x2<=0:xx=[[-x2,-x1]]
else:xx=[[1,-x1],[0,x2]]
if y1>=0: yy=[[y1,y2]]
elif y2<=0:yy=[[-y2,-y1]]
else:yy=[[1,-y1],[0,y2]]
ans=0
for x in xx:
    for y in yy:
        if x[0]+y[0]>d:continue
        if x[1]+y[1]<=d:
            ans+=(x[1]-x[0]+1)*(y[1]-y[0]+1)
            continue
        if x[1]+y[0] >= d:
            if x[0]+y[1]>=d:
                tx=d-y[0]
                ans+=sumn(tx-x[0]+1)
            else:
                tx=d-y[1]
                e=y[1]-y[0]+1
                ans+=sumn(e)+e*(tx-x[0])
        else:
            if x[0]+y[1]>=d:
                ty=d-x[1]
                e=x[1]-x[0]+1
                ans+=sumn(e)+e*(ty-y[0])
            else:
                tx=d-y[1]
                ans+=(x[1]-x[0]+1)*(y[1]-y[0]+1)-sumn(x[1]-tx)
print ans
0