結果
問題 | No.325 マンハッタン距離2 |
ユーザー | tjake |
提出日時 | 2015-12-18 02:48:39 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 12 ms / 1,000 ms |
コード長 | 1,055 bytes |
コンパイル時間 | 64 ms |
コンパイル使用メモリ | 6,812 KB |
実行使用メモリ | 6,116 KB |
最終ジャッジ日時 | 2023-10-14 13:41:51 |
合計ジャッジ時間 | 1,473 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 12 ms
5,896 KB |
testcase_01 | AC | 11 ms
6,072 KB |
testcase_02 | AC | 12 ms
5,960 KB |
testcase_03 | AC | 11 ms
5,872 KB |
testcase_04 | AC | 11 ms
5,896 KB |
testcase_05 | AC | 11 ms
6,116 KB |
testcase_06 | AC | 11 ms
6,008 KB |
testcase_07 | AC | 11 ms
6,012 KB |
testcase_08 | AC | 11 ms
6,112 KB |
testcase_09 | AC | 11 ms
5,880 KB |
testcase_10 | AC | 11 ms
5,964 KB |
testcase_11 | AC | 11 ms
6,072 KB |
testcase_12 | AC | 11 ms
6,012 KB |
testcase_13 | AC | 11 ms
6,100 KB |
testcase_14 | AC | 10 ms
5,900 KB |
testcase_15 | AC | 11 ms
6,072 KB |
testcase_16 | AC | 11 ms
5,956 KB |
testcase_17 | AC | 11 ms
5,884 KB |
testcase_18 | AC | 11 ms
5,956 KB |
testcase_19 | AC | 11 ms
6,016 KB |
testcase_20 | AC | 11 ms
5,952 KB |
testcase_21 | AC | 11 ms
6,064 KB |
testcase_22 | AC | 11 ms
5,960 KB |
testcase_23 | AC | 11 ms
6,016 KB |
testcase_24 | AC | 11 ms
5,952 KB |
testcase_25 | AC | 11 ms
6,012 KB |
testcase_26 | AC | 11 ms
6,016 KB |
ソースコード
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