結果

問題 No.960 マンハッタン距離3
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-12-25 18:16:28
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 7,623 bytes
コンパイル時間 1,268 ms
コンパイル使用メモリ 130,788 KB
実行使用メモリ 17,980 KB
最終ジャッジ日時 2024-06-22 04:02:55
合計ジャッジ時間 13,478 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 WA -
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 1 ms
6,940 KB
testcase_30 AC 1 ms
6,940 KB
testcase_31 AC 1 ms
6,944 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 2 ms
6,940 KB
testcase_36 AC 1 ms
6,944 KB
testcase_37 AC 1 ms
6,944 KB
testcase_38 WA -
testcase_39 AC 1 ms
6,944 KB
testcase_40 AC 1 ms
6,944 KB
testcase_41 AC 1 ms
6,940 KB
testcase_42 AC 1 ms
6,944 KB
testcase_43 AC 1 ms
6,944 KB
testcase_44 AC 1 ms
6,940 KB
testcase_45 AC 1 ms
6,944 KB
testcase_46 AC 1 ms
6,940 KB
testcase_47 AC 1 ms
6,944 KB
testcase_48 AC 1 ms
6,940 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 2 ms
6,944 KB
testcase_51 AC 1 ms
6,944 KB
testcase_52 AC 1 ms
6,940 KB
testcase_53 AC 1 ms
6,940 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,940 KB
testcase_58 AC 1 ms
6,940 KB
testcase_59 AC 2 ms
6,944 KB
testcase_60 AC 2 ms
6,944 KB
testcase_61 AC 1 ms
6,944 KB
testcase_62 AC 1 ms
6,944 KB
testcase_63 AC 1 ms
6,944 KB
testcase_64 AC 2 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,940 KB
testcase_68 AC 1 ms
6,944 KB
testcase_69 AC 1 ms
6,944 KB
testcase_70 AC 2 ms
6,940 KB
testcase_71 AC 1 ms
6,944 KB
testcase_72 AC 2 ms
6,940 KB
testcase_73 AC 2 ms
6,940 KB
testcase_74 AC 1 ms
6,940 KB
testcase_75 AC 2 ms
6,940 KB
testcase_76 AC 1 ms
6,940 KB
testcase_77 AC 1 ms
6,940 KB
testcase_78 AC 1 ms
6,940 KB
testcase_79 AC 1 ms
6,940 KB
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 1 ms
6,940 KB
testcase_83 AC 1 ms
6,944 KB
testcase_84 AC 1 ms
6,944 KB
testcase_85 AC 1 ms
6,940 KB
testcase_86 AC 1 ms
6,944 KB
testcase_87 WA -
testcase_88 AC 1 ms
6,940 KB
testcase_89 WA -
testcase_90 AC 2 ms
6,940 KB
testcase_91 WA -
testcase_92 AC 1 ms
6,944 KB
testcase_93 AC 1 ms
6,940 KB
testcase_94 WA -
testcase_95 AC 1 ms
6,944 KB
testcase_96 AC 1 ms
6,940 KB
testcase_97 WA -
testcase_98 AC 1 ms
6,944 KB
testcase_99 AC 1 ms
6,940 KB
testcase_100 WA -
testcase_101 WA -
testcase_102 AC 1 ms
6,940 KB
testcase_103 WA -
testcase_104 AC 1 ms
6,940 KB
testcase_105 AC 1 ms
6,944 KB
testcase_106 WA -
testcase_107 AC 1 ms
6,940 KB
testcase_108 WA -
testcase_109 WA -
testcase_110 AC 1 ms
6,940 KB
testcase_111 AC 1 ms
6,940 KB
testcase_112 AC 1 ms
6,940 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 WA -
testcase_117 WA -
testcase_118 AC 1 ms
6,940 KB
testcase_119 AC 1 ms
6,940 KB
testcase_120 WA -
testcase_121 AC 1 ms
6,944 KB
testcase_122 AC 1 ms
6,940 KB
testcase_123 WA -
testcase_124 AC 1 ms
6,940 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 73 ms
10,440 KB
testcase_130 AC 49 ms
6,960 KB
testcase_131 AC 85 ms
12,140 KB
testcase_132 AC 87 ms
11,464 KB
testcase_133 AC 2 ms
6,944 KB
testcase_134 AC 25 ms
6,948 KB
testcase_135 AC 30 ms
6,940 KB
testcase_136 AC 30 ms
6,944 KB
testcase_137 AC 43 ms
6,940 KB
testcase_138 AC 65 ms
12,108 KB
testcase_139 AC 75 ms
8,408 KB
testcase_140 AC 92 ms
9,972 KB
testcase_141 AC 97 ms
10,176 KB
testcase_142 AC 42 ms
6,940 KB
testcase_143 AC 57 ms
7,172 KB
testcase_144 WA -
testcase_145 WA -
testcase_146 WA -
testcase_147 WA -
testcase_148 AC 37 ms
6,944 KB
testcase_149 AC 55 ms
7,276 KB
testcase_150 AC 84 ms
15,176 KB
testcase_151 AC 5 ms
6,940 KB
testcase_152 AC 63 ms
7,816 KB
testcase_153 AC 95 ms
10,292 KB
testcase_154 AC 4 ms
6,940 KB
testcase_155 AC 73 ms
8,480 KB
testcase_156 AC 26 ms
6,944 KB
testcase_157 AC 74 ms
9,880 KB
testcase_158 AC 96 ms
17,980 KB
testcase_159 AC 14 ms
6,940 KB
testcase_160 AC 6 ms
6,944 KB
testcase_161 AC 84 ms
10,916 KB
testcase_162 AC 82 ms
9,780 KB
testcase_163 AC 46 ms
6,940 KB
testcase_164 AC 98 ms
13,920 KB
testcase_165 AC 76 ms
9,204 KB
testcase_166 AC 14 ms
6,944 KB
testcase_167 AC 46 ms
6,944 KB
testcase_168 AC 35 ms
6,940 KB
testcase_169 AC 38 ms
6,944 KB
testcase_170 AC 32 ms
6,944 KB
testcase_171 AC 54 ms
6,944 KB
testcase_172 AC 37 ms
6,940 KB
testcase_173 AC 9 ms
6,944 KB
testcase_174 AC 81 ms
9,464 KB
testcase_175 AC 102 ms
12,108 KB
testcase_176 AC 69 ms
8,052 KB
testcase_177 AC 10 ms
6,940 KB
testcase_178 AC 73 ms
9,792 KB
testcase_179 AC 77 ms
14,588 KB
testcase_180 AC 95 ms
11,768 KB
testcase_181 AC 21 ms
6,940 KB
testcase_182 AC 42 ms
6,940 KB
testcase_183 AC 58 ms
7,412 KB
testcase_184 AC 43 ms
6,940 KB
testcase_185 AC 69 ms
8,440 KB
testcase_186 AC 84 ms
9,796 KB
testcase_187 AC 66 ms
9,492 KB
testcase_188 AC 1 ms
6,940 KB
testcase_189 AC 1 ms
6,944 KB
testcase_190 WA -
testcase_191 WA -
testcase_192 WA -
testcase_193 AC 2 ms
6,940 KB
testcase_194 AC 2 ms
6,944 KB
testcase_195 AC 1 ms
6,940 KB
testcase_196 WA -
testcase_197 WA -
testcase_198 WA -
testcase_199 WA -
testcase_200 AC 75 ms
9,892 KB
testcase_201 AC 42 ms
6,944 KB
testcase_202 WA -
testcase_203 WA -
testcase_204 WA -
testcase_205 WA -
testcase_206 AC 81 ms
10,248 KB
testcase_207 AC 61 ms
9,276 KB
testcase_208 WA -
testcase_209 WA -
testcase_210 WA -
testcase_211 WA -
testcase_212 AC 20 ms
6,944 KB
testcase_213 AC 44 ms
7,248 KB
testcase_214 WA -
testcase_215 WA -
testcase_216 WA -
testcase_217 WA -
testcase_218 AC 88 ms
10,304 KB
testcase_219 AC 46 ms
6,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
            }
            ans += max(as[0] - aL, 0) * max(aU - as[$ - 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);
            }
            ans += max(bs[0] - bL, 0) * max(bU - bs[$ - 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) {
  }
}
0