結果

問題 No.960 マンハッタン距離3
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-12-25 18:16:28
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 7,623 bytes
コンパイル時間 2,217 ms
コンパイル使用メモリ 117,392 KB
実行使用メモリ 20,204 KB
最終ジャッジ日時 2023-09-04 04:31:14
合計ジャッジ時間 17,794 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 WA -
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 1 ms
4,376 KB
testcase_53 AC 1 ms
4,380 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,384 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 AC 2 ms
4,376 KB
testcase_60 AC 2 ms
4,380 KB
testcase_61 AC 2 ms
4,380 KB
testcase_62 AC 1 ms
4,380 KB
testcase_63 AC 2 ms
4,380 KB
testcase_64 AC 2 ms
4,376 KB
testcase_65 AC 2 ms
4,376 KB
testcase_66 AC 2 ms
4,380 KB
testcase_67 AC 2 ms
4,376 KB
testcase_68 AC 2 ms
4,380 KB
testcase_69 AC 2 ms
4,376 KB
testcase_70 AC 1 ms
4,380 KB
testcase_71 AC 1 ms
4,376 KB
testcase_72 AC 2 ms
4,376 KB
testcase_73 AC 2 ms
4,380 KB
testcase_74 AC 1 ms
4,376 KB
testcase_75 AC 2 ms
4,384 KB
testcase_76 AC 2 ms
4,380 KB
testcase_77 AC 2 ms
4,380 KB
testcase_78 AC 2 ms
4,376 KB
testcase_79 AC 1 ms
4,380 KB
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 1 ms
4,376 KB
testcase_83 AC 2 ms
4,376 KB
testcase_84 AC 1 ms
4,380 KB
testcase_85 AC 2 ms
4,376 KB
testcase_86 AC 1 ms
4,376 KB
testcase_87 WA -
testcase_88 AC 1 ms
4,376 KB
testcase_89 WA -
testcase_90 AC 1 ms
4,380 KB
testcase_91 WA -
testcase_92 AC 1 ms
4,376 KB
testcase_93 AC 2 ms
4,376 KB
testcase_94 WA -
testcase_95 AC 1 ms
4,376 KB
testcase_96 AC 1 ms
4,376 KB
testcase_97 WA -
testcase_98 AC 1 ms
4,376 KB
testcase_99 AC 1 ms
4,376 KB
testcase_100 WA -
testcase_101 WA -
testcase_102 AC 2 ms
4,376 KB
testcase_103 WA -
testcase_104 AC 1 ms
4,380 KB
testcase_105 AC 2 ms
4,376 KB
testcase_106 WA -
testcase_107 AC 2 ms
4,380 KB
testcase_108 WA -
testcase_109 WA -
testcase_110 AC 1 ms
4,380 KB
testcase_111 AC 2 ms
4,376 KB
testcase_112 AC 2 ms
4,380 KB
testcase_113 AC 2 ms
4,380 KB
testcase_114 AC 1 ms
4,376 KB
testcase_115 AC 1 ms
4,380 KB
testcase_116 WA -
testcase_117 WA -
testcase_118 AC 1 ms
4,376 KB
testcase_119 AC 1 ms
4,380 KB
testcase_120 WA -
testcase_121 AC 1 ms
4,376 KB
testcase_122 AC 1 ms
4,380 KB
testcase_123 WA -
testcase_124 AC 2 ms
4,380 KB
testcase_125 AC 2 ms
4,384 KB
testcase_126 AC 1 ms
4,376 KB
testcase_127 AC 1 ms
4,380 KB
testcase_128 AC 27 ms
6,520 KB
testcase_129 AC 74 ms
8,896 KB
testcase_130 AC 50 ms
7,368 KB
testcase_131 AC 91 ms
18,112 KB
testcase_132 AC 90 ms
11,164 KB
testcase_133 AC 3 ms
4,380 KB
testcase_134 AC 25 ms
5,932 KB
testcase_135 AC 31 ms
7,572 KB
testcase_136 AC 31 ms
7,256 KB
testcase_137 AC 47 ms
6,776 KB
testcase_138 AC 67 ms
10,876 KB
testcase_139 AC 80 ms
10,960 KB
testcase_140 AC 97 ms
11,604 KB
testcase_141 AC 103 ms
18,784 KB
testcase_142 AC 44 ms
7,160 KB
testcase_143 AC 60 ms
7,576 KB
testcase_144 WA -
testcase_145 WA -
testcase_146 WA -
testcase_147 WA -
testcase_148 AC 37 ms
6,532 KB
testcase_149 AC 58 ms
7,600 KB
testcase_150 AC 84 ms
9,740 KB
testcase_151 AC 7 ms
4,380 KB
testcase_152 AC 65 ms
8,100 KB
testcase_153 AC 98 ms
18,096 KB
testcase_154 AC 5 ms
4,380 KB
testcase_155 AC 77 ms
14,744 KB
testcase_156 AC 26 ms
5,208 KB
testcase_157 AC 76 ms
14,392 KB
testcase_158 AC 99 ms
17,284 KB
testcase_159 AC 15 ms
4,732 KB
testcase_160 AC 7 ms
4,380 KB
testcase_161 AC 87 ms
17,664 KB
testcase_162 AC 86 ms
17,380 KB
testcase_163 AC 47 ms
6,748 KB
testcase_164 AC 97 ms
11,532 KB
testcase_165 AC 77 ms
14,672 KB
testcase_166 AC 14 ms
4,708 KB
testcase_167 AC 48 ms
8,096 KB
testcase_168 AC 36 ms
7,528 KB
testcase_169 AC 39 ms
7,052 KB
testcase_170 AC 31 ms
5,528 KB
testcase_171 AC 56 ms
8,312 KB
testcase_172 AC 38 ms
6,480 KB
testcase_173 AC 9 ms
4,380 KB
testcase_174 AC 85 ms
16,348 KB
testcase_175 AC 106 ms
18,724 KB
testcase_176 AC 72 ms
14,324 KB
testcase_177 AC 11 ms
4,516 KB
testcase_178 AC 75 ms
8,564 KB
testcase_179 AC 79 ms
12,276 KB
testcase_180 AC 96 ms
11,616 KB
testcase_181 AC 21 ms
4,940 KB
testcase_182 AC 42 ms
6,468 KB
testcase_183 AC 59 ms
7,800 KB
testcase_184 AC 45 ms
7,044 KB
testcase_185 AC 71 ms
10,092 KB
testcase_186 AC 89 ms
10,608 KB
testcase_187 AC 66 ms
9,292 KB
testcase_188 AC 1 ms
4,380 KB
testcase_189 AC 1 ms
4,376 KB
testcase_190 WA -
testcase_191 WA -
testcase_192 WA -
testcase_193 AC 2 ms
4,376 KB
testcase_194 AC 2 ms
4,376 KB
testcase_195 AC 1 ms
4,376 KB
testcase_196 WA -
testcase_197 WA -
testcase_198 WA -
testcase_199 WA -
testcase_200 AC 78 ms
15,268 KB
testcase_201 AC 44 ms
8,040 KB
testcase_202 WA -
testcase_203 WA -
testcase_204 WA -
testcase_205 WA -
testcase_206 AC 87 ms
18,068 KB
testcase_207 AC 64 ms
12,648 KB
testcase_208 WA -
testcase_209 WA -
testcase_210 WA -
testcase_211 WA -
testcase_212 AC 21 ms
4,968 KB
testcase_213 AC 45 ms
9,040 KB
testcase_214 WA -
testcase_215 WA -
testcase_216 WA -
testcase_217 WA -
testcase_218 AC 92 ms
18,452 KB
testcase_219 AC 48 ms
10,096 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