結果
問題 | No.960 マンハッタン距離3 |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-12-25 18:38:55 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 106 ms / 2,000 ms |
コード長 | 7,751 bytes |
コンパイル時間 | 1,510 ms |
コンパイル使用メモリ | 130,536 KB |
実行使用メモリ | 17,084 KB |
最終ジャッジ日時 | 2024-06-22 04:03:19 |
合計ジャッジ時間 | 11,863 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,820 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,944 KB |
testcase_12 | AC | 1 ms
6,944 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 1 ms
6,940 KB |
testcase_15 | AC | 1 ms
6,944 KB |
testcase_16 | AC | 1 ms
6,944 KB |
testcase_17 | AC | 1 ms
6,944 KB |
testcase_18 | AC | 1 ms
6,940 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 1 ms
6,944 KB |
testcase_21 | AC | 1 ms
6,940 KB |
testcase_22 | AC | 2 ms
6,944 KB |
testcase_23 | AC | 1 ms
6,940 KB |
testcase_24 | AC | 1 ms
6,944 KB |
testcase_25 | AC | 1 ms
6,944 KB |
testcase_26 | AC | 1 ms
6,940 KB |
testcase_27 | AC | 1 ms
6,944 KB |
testcase_28 | AC | 2 ms
6,944 KB |
testcase_29 | AC | 1 ms
6,940 KB |
testcase_30 | AC | 2 ms
6,944 KB |
testcase_31 | AC | 1 ms
6,940 KB |
testcase_32 | AC | 1 ms
6,940 KB |
testcase_33 | AC | 1 ms
6,940 KB |
testcase_34 | AC | 2 ms
6,944 KB |
testcase_35 | AC | 1 ms
6,944 KB |
testcase_36 | AC | 1 ms
6,940 KB |
testcase_37 | AC | 1 ms
6,940 KB |
testcase_38 | AC | 1 ms
6,940 KB |
testcase_39 | AC | 1 ms
6,944 KB |
testcase_40 | AC | 1 ms
6,940 KB |
testcase_41 | AC | 1 ms
6,940 KB |
testcase_42 | AC | 1 ms
6,944 KB |
testcase_43 | AC | 1 ms
6,940 KB |
testcase_44 | AC | 1 ms
6,944 KB |
testcase_45 | AC | 1 ms
6,940 KB |
testcase_46 | AC | 1 ms
6,940 KB |
testcase_47 | AC | 1 ms
6,940 KB |
testcase_48 | AC | 2 ms
6,940 KB |
testcase_49 | AC | 1 ms
6,940 KB |
testcase_50 | AC | 1 ms
6,944 KB |
testcase_51 | AC | 2 ms
6,940 KB |
testcase_52 | AC | 2 ms
6,940 KB |
testcase_53 | AC | 2 ms
6,944 KB |
testcase_54 | AC | 1 ms
6,940 KB |
testcase_55 | AC | 1 ms
6,940 KB |
testcase_56 | AC | 1 ms
6,940 KB |
testcase_57 | AC | 1 ms
6,944 KB |
testcase_58 | AC | 1 ms
6,944 KB |
testcase_59 | AC | 1 ms
6,940 KB |
testcase_60 | AC | 1 ms
6,940 KB |
testcase_61 | AC | 2 ms
6,940 KB |
testcase_62 | AC | 1 ms
6,940 KB |
testcase_63 | AC | 2 ms
6,944 KB |
testcase_64 | AC | 1 ms
6,940 KB |
testcase_65 | AC | 1 ms
6,940 KB |
testcase_66 | AC | 1 ms
6,940 KB |
testcase_67 | AC | 1 ms
6,944 KB |
testcase_68 | AC | 1 ms
6,940 KB |
testcase_69 | AC | 1 ms
6,948 KB |
testcase_70 | AC | 1 ms
6,940 KB |
testcase_71 | AC | 1 ms
6,940 KB |
testcase_72 | AC | 2 ms
6,944 KB |
testcase_73 | AC | 2 ms
6,940 KB |
testcase_74 | AC | 1 ms
6,940 KB |
testcase_75 | AC | 2 ms
6,944 KB |
testcase_76 | AC | 1 ms
6,944 KB |
testcase_77 | AC | 1 ms
6,944 KB |
testcase_78 | AC | 1 ms
6,940 KB |
testcase_79 | AC | 1 ms
6,940 KB |
testcase_80 | AC | 1 ms
6,944 KB |
testcase_81 | AC | 1 ms
6,944 KB |
testcase_82 | AC | 2 ms
6,940 KB |
testcase_83 | AC | 2 ms
6,940 KB |
testcase_84 | AC | 1 ms
6,940 KB |
testcase_85 | AC | 1 ms
6,944 KB |
testcase_86 | AC | 1 ms
6,940 KB |
testcase_87 | AC | 1 ms
6,940 KB |
testcase_88 | AC | 2 ms
6,940 KB |
testcase_89 | AC | 1 ms
6,940 KB |
testcase_90 | AC | 1 ms
6,944 KB |
testcase_91 | AC | 2 ms
6,944 KB |
testcase_92 | AC | 1 ms
6,944 KB |
testcase_93 | AC | 1 ms
6,940 KB |
testcase_94 | AC | 1 ms
6,944 KB |
testcase_95 | AC | 1 ms
6,944 KB |
testcase_96 | AC | 1 ms
6,940 KB |
testcase_97 | AC | 1 ms
6,940 KB |
testcase_98 | AC | 1 ms
6,940 KB |
testcase_99 | AC | 1 ms
6,940 KB |
testcase_100 | AC | 1 ms
6,944 KB |
testcase_101 | AC | 1 ms
6,944 KB |
testcase_102 | AC | 1 ms
6,940 KB |
testcase_103 | AC | 1 ms
6,944 KB |
testcase_104 | AC | 1 ms
6,940 KB |
testcase_105 | AC | 1 ms
6,940 KB |
testcase_106 | AC | 1 ms
6,944 KB |
testcase_107 | AC | 1 ms
6,944 KB |
testcase_108 | AC | 1 ms
6,940 KB |
testcase_109 | AC | 1 ms
6,940 KB |
testcase_110 | AC | 1 ms
6,940 KB |
testcase_111 | AC | 1 ms
6,940 KB |
testcase_112 | AC | 1 ms
6,944 KB |
testcase_113 | AC | 1 ms
6,944 KB |
testcase_114 | AC | 1 ms
6,940 KB |
testcase_115 | AC | 1 ms
6,940 KB |
testcase_116 | AC | 1 ms
6,940 KB |
testcase_117 | AC | 1 ms
6,944 KB |
testcase_118 | AC | 1 ms
6,944 KB |
testcase_119 | AC | 1 ms
6,940 KB |
testcase_120 | AC | 2 ms
6,940 KB |
testcase_121 | AC | 1 ms
6,944 KB |
testcase_122 | AC | 1 ms
6,940 KB |
testcase_123 | AC | 1 ms
6,940 KB |
testcase_124 | AC | 2 ms
6,944 KB |
testcase_125 | AC | 1 ms
6,940 KB |
testcase_126 | AC | 1 ms
6,944 KB |
testcase_127 | AC | 1 ms
6,940 KB |
testcase_128 | AC | 27 ms
6,944 KB |
testcase_129 | AC | 77 ms
10,748 KB |
testcase_130 | AC | 52 ms
6,944 KB |
testcase_131 | AC | 87 ms
10,836 KB |
testcase_132 | AC | 91 ms
9,844 KB |
testcase_133 | AC | 2 ms
6,940 KB |
testcase_134 | AC | 25 ms
6,944 KB |
testcase_135 | AC | 29 ms
6,940 KB |
testcase_136 | AC | 31 ms
6,940 KB |
testcase_137 | AC | 45 ms
6,940 KB |
testcase_138 | AC | 68 ms
11,172 KB |
testcase_139 | AC | 78 ms
10,420 KB |
testcase_140 | AC | 96 ms
11,356 KB |
testcase_141 | AC | 100 ms
10,548 KB |
testcase_142 | AC | 43 ms
6,940 KB |
testcase_143 | AC | 60 ms
7,288 KB |
testcase_144 | AC | 85 ms
10,184 KB |
testcase_145 | AC | 7 ms
6,944 KB |
testcase_146 | AC | 21 ms
6,944 KB |
testcase_147 | AC | 69 ms
7,892 KB |
testcase_148 | AC | 37 ms
6,940 KB |
testcase_149 | AC | 57 ms
7,300 KB |
testcase_150 | AC | 86 ms
9,252 KB |
testcase_151 | AC | 6 ms
6,940 KB |
testcase_152 | AC | 66 ms
7,676 KB |
testcase_153 | AC | 99 ms
11,240 KB |
testcase_154 | AC | 4 ms
6,940 KB |
testcase_155 | AC | 74 ms
8,260 KB |
testcase_156 | AC | 26 ms
6,940 KB |
testcase_157 | AC | 76 ms
10,288 KB |
testcase_158 | AC | 98 ms
17,084 KB |
testcase_159 | AC | 15 ms
6,944 KB |
testcase_160 | AC | 5 ms
6,940 KB |
testcase_161 | AC | 83 ms
9,936 KB |
testcase_162 | AC | 81 ms
9,200 KB |
testcase_163 | AC | 53 ms
6,944 KB |
testcase_164 | AC | 100 ms
13,508 KB |
testcase_165 | AC | 75 ms
10,160 KB |
testcase_166 | AC | 15 ms
6,940 KB |
testcase_167 | AC | 47 ms
6,944 KB |
testcase_168 | AC | 35 ms
6,940 KB |
testcase_169 | AC | 36 ms
6,940 KB |
testcase_170 | AC | 31 ms
6,940 KB |
testcase_171 | AC | 52 ms
6,940 KB |
testcase_172 | AC | 38 ms
6,948 KB |
testcase_173 | AC | 9 ms
6,940 KB |
testcase_174 | AC | 81 ms
9,168 KB |
testcase_175 | AC | 106 ms
12,364 KB |
testcase_176 | AC | 71 ms
8,096 KB |
testcase_177 | AC | 10 ms
6,940 KB |
testcase_178 | AC | 77 ms
8,308 KB |
testcase_179 | AC | 80 ms
12,392 KB |
testcase_180 | AC | 99 ms
11,188 KB |
testcase_181 | AC | 22 ms
6,944 KB |
testcase_182 | AC | 43 ms
6,940 KB |
testcase_183 | AC | 61 ms
7,380 KB |
testcase_184 | AC | 45 ms
6,944 KB |
testcase_185 | AC | 73 ms
10,284 KB |
testcase_186 | AC | 88 ms
10,096 KB |
testcase_187 | AC | 68 ms
7,704 KB |
testcase_188 | AC | 1 ms
6,944 KB |
testcase_189 | AC | 1 ms
6,940 KB |
testcase_190 | AC | 1 ms
6,940 KB |
testcase_191 | AC | 1 ms
6,940 KB |
testcase_192 | AC | 1 ms
6,944 KB |
testcase_193 | AC | 1 ms
6,940 KB |
testcase_194 | AC | 1 ms
6,940 KB |
testcase_195 | AC | 1 ms
6,944 KB |
testcase_196 | AC | 63 ms
7,612 KB |
testcase_197 | AC | 19 ms
6,940 KB |
testcase_198 | AC | 47 ms
6,944 KB |
testcase_199 | AC | 69 ms
10,060 KB |
testcase_200 | AC | 77 ms
8,676 KB |
testcase_201 | AC | 44 ms
6,944 KB |
testcase_202 | AC | 74 ms
9,904 KB |
testcase_203 | AC | 39 ms
6,944 KB |
testcase_204 | AC | 96 ms
10,572 KB |
testcase_205 | AC | 47 ms
6,944 KB |
testcase_206 | AC | 83 ms
10,144 KB |
testcase_207 | AC | 62 ms
7,636 KB |
testcase_208 | AC | 70 ms
8,136 KB |
testcase_209 | AC | 22 ms
6,944 KB |
testcase_210 | AC | 11 ms
6,944 KB |
testcase_211 | AC | 33 ms
6,944 KB |
testcase_212 | AC | 22 ms
6,940 KB |
testcase_213 | AC | 46 ms
6,940 KB |
testcase_214 | AC | 98 ms
10,624 KB |
testcase_215 | AC | 83 ms
8,804 KB |
testcase_216 | AC | 94 ms
10,156 KB |
testcase_217 | AC | 52 ms
6,984 KB |
testcase_218 | AC | 90 ms
10,376 KB |
testcase_219 | AC | 46 ms
6,940 KB |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } void main() { try { for (; ; ) { const W = readLong(); const H = readLong(); const N = readInt(); auto X = new long[N]; auto Y = new long[N]; foreach (i; 0 .. N) { X[i] = readLong(); Y[i] = readLong(); } auto A = new long[N]; auto B = new long[N]; foreach (i; 0 .. N) { A[i] = X[i] + Y[i]; B[i] = -X[i] + Y[i]; } const as = A.dup.sort.uniq.array; const bs = B.dup.sort.uniq.array; debug { writeln("A = ", A); writeln("B = ", B); writeln("as = ", as); writeln("bs = ", bs); } bool check(long ca, long cb, long sz) { const cx = (ca - cb) / 2; const cy = (ca + cb) / 2; if (!(1 <= cx && cx <= W && 1 <= cy && cy <= H)) { return false; } foreach (i; 0 .. N) { if (sz != max(abs(A[i] - ca), abs(B[i] - cb))) { return false; } } debug { writeln("check ", ca, " ", cb, " ", sz, " = true"); } return true; } long ans; if (A.map!(a => (a & 1)).array.sort.uniq.array.length == 1 && B.map!(a => (a & 1)).array.sort.uniq.array.length == 1) { if (as.length == 1 && bs.length == 1) { ans = H * W; } if (as.length == 1) { /* ## ## o o o ## ## */ const i0 = X.minIndex; const i1 = X.maxIndex; ans += (X[i0] - 1 + 1) * (Y[i1] - 1 + 1); ans += (W - X[i1] + 1) * (H - Y[i0] + 1); if (N == 2) { ans += (X[i1] - X[i0] - 1); } } else if (bs.length == 1) { /* ## ## o o o ## ## */ const i0 = X.minIndex; const i1 = X.maxIndex; ans += (X[i0] - 1 + 1) * (H - Y[i1] + 1); ans += (W - X[i1] + 1) * (Y[i0] - 1 + 1); if (N == 2) { ans += (X[i1] - X[i0] - 1); } } else { // no as[0], as[$ - 1] if (bs.length == 2) { const sz = (bs[$ - 1] - bs[0]) / 2; const cb = bs[0] + sz; // x = 1 or y = 1 long aL = max(1 + (cb + 1), (1 - cb) + 1); // x = W or y = H long aU = min(W + (cb + W), (H - cb) + H); foreach (i; 0 .. N) { chmax(aL, A[i] - sz); chmin(aU, A[i] + sz); } chmax(aL, as[$ - 1] - sz + 2); chmin(aU, as[0] + sz - 2); ans += max((aU - aL) / 2 + 1, 0); } // no bs[0], bs[$ - 1] if (as.length == 2) { const sz = (as[$ - 1] - as[0]) / 2; const ca = as[0] + sz; // x = W or y = 1 long bL = max(-W + (ca - W), -(ca - 1) + 1); // x = 1 or y = H long bU = min(-1 + (ca - 1), -(ca - H) + H); foreach (i; 0 .. N) { chmax(bL, B[i] - sz); chmin(bU, B[i] + sz); } chmax(bL, bs[$ - 1] - sz + 2); chmin(bU, bs[0] + sz - 2); ans += max((bU - bL) / 2 + 1, 0); } // [as[0], *] x [bs[0], *] { long sz; long yL = (as[0] + bs[0]) / 2; foreach (i; 0 .. N) { if (A[i] == as[0] || B[i] == bs[0]) { chmax(yL, Y[i]); } else { chmax(sz, max(A[i] - as[0], B[i] - bs[0]) / 2); } } if (sz) { if (check(as[0] + sz, bs[0] + sz, sz)) ans += 1; } else { ans += max(H - yL + 1, 0); } } // [as[0], *] x [*, bs[$ - 1]] { long sz; long xL = (as[0] - bs[$ - 1]) / 2; foreach (i; 0 .. N) { if (A[i] == as[0] || B[i] == bs[$ - 1]) { chmax(xL, X[i]); } else { chmax(sz, max(A[i] - as[0], bs[$ - 1] - B[i]) / 2); } } if (sz) { if (check(as[0] + sz, bs[$ - 1] - sz, sz)) ans += 1; } else { ans += max(W - xL + 1, 0); } } // [as[0], *] x [bs[0], bs[$ - 1]] { const sz = (bs[$ - 1] - bs[0]) / 2; if (check(as[0] + sz, bs[0] + sz, sz)) ans -= 1; } // [*, as[$ - 1]] x [bs[0], *] { long sz; long xU = (as[$ - 1] - bs[0]) / 2; foreach (i; 0 .. N) { if (A[i] == as[$ - 1] || B[i] == bs[0]) { chmin(xU, X[i]); } else { chmax(sz, max(as[$ - 1] - A[i], B[i] - bs[0]) / 2); } } if (sz) { if (check(as[$ - 1] - sz, bs[0] + sz, sz)) ans += 1; } else { ans += max(xU - 1 + 1, 0); } } // [*, as[$ - 1]] x [*, bs[$ - 1]] { long sz; long yU = (as[$ - 1] + bs[$ - 1]) / 2; foreach (i; 0 .. N) { if (A[i] == as[$ - 1] || B[i] == bs[$ - 1]) { chmin(yU, Y[i]); } else { chmax(sz, max(as[$ - 1] - A[i], bs[$ - 1] - B[i]) / 2); } } if (sz) { if (check(as[$ - 1] - sz, bs[$ - 1] - sz, sz)) ans += 1; } else { ans += max(yU - 1 + 1, 0); } } // [*, as[$ - 1]] x [bs[0], bs[$ - 1]] { const sz = (bs[$ - 1] - bs[0]) / 2; if (check(as[$ - 1] - sz, bs[0] + sz, sz)) ans -= 1; } // [as[0], as[$ - 1]] x [bs[0], *] { const sz = (as[$ - 1] - as[0]) / 2; if (check(as[0] + sz, bs[0] + sz, sz)) ans -= 1; } // [as[0], as[$ - 1]] x [*, bs[$ - 1]] { const sz = (as[$ - 1] - as[0]) / 2; if (check(as[0] + sz, bs[$ - 1] - sz, sz)) ans -= 1; } // [as[0], as[$ - 1]] x [bs[0], bs[$ - 1]] if (as[$ - 1] - as[0] == bs[$ - 1] - bs[0]) { const sz = (as[$ - 1] - as[0]) / 2; if (check(as[0] + sz, bs[0] + sz, sz)) ans += 1; } } } writeln(ans); } } catch (EOFException e) { } }