結果

問題 No.960 マンハッタン距離3
ユーザー risujirohrisujiroh
提出日時 2019-12-23 03:11:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 6,066 bytes
コンパイル時間 1,816 ms
コンパイル使用メモリ 176,600 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-09-15 01:45:46
合計ジャッジ時間 9,599 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 AC 3 ms
5,376 KB
testcase_33 AC 3 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 3 ms
5,376 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 3 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 3 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 3 ms
5,376 KB
testcase_45 AC 3 ms
5,376 KB
testcase_46 AC 3 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 3 ms
5,376 KB
testcase_50 AC 3 ms
5,376 KB
testcase_51 AC 3 ms
5,376 KB
testcase_52 AC 3 ms
5,376 KB
testcase_53 AC 3 ms
5,376 KB
testcase_54 AC 3 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
testcase_56 AC 3 ms
5,376 KB
testcase_57 AC 3 ms
5,376 KB
testcase_58 AC 3 ms
5,376 KB
testcase_59 AC 3 ms
5,376 KB
testcase_60 AC 3 ms
5,376 KB
testcase_61 AC 3 ms
5,376 KB
testcase_62 AC 3 ms
5,376 KB
testcase_63 AC 3 ms
5,376 KB
testcase_64 AC 3 ms
5,376 KB
testcase_65 AC 3 ms
5,376 KB
testcase_66 AC 3 ms
5,376 KB
testcase_67 AC 3 ms
5,376 KB
testcase_68 AC 3 ms
5,376 KB
testcase_69 AC 2 ms
5,376 KB
testcase_70 AC 3 ms
5,376 KB
testcase_71 AC 3 ms
5,376 KB
testcase_72 AC 3 ms
5,376 KB
testcase_73 AC 3 ms
5,376 KB
testcase_74 AC 3 ms
5,376 KB
testcase_75 AC 3 ms
5,376 KB
testcase_76 AC 2 ms
5,376 KB
testcase_77 AC 3 ms
5,376 KB
testcase_78 AC 3 ms
5,376 KB
testcase_79 AC 3 ms
5,376 KB
testcase_80 AC 3 ms
5,376 KB
testcase_81 AC 3 ms
5,376 KB
testcase_82 AC 2 ms
5,376 KB
testcase_83 AC 3 ms
5,376 KB
testcase_84 AC 3 ms
5,376 KB
testcase_85 AC 3 ms
5,376 KB
testcase_86 AC 2 ms
5,376 KB
testcase_87 AC 3 ms
5,376 KB
testcase_88 AC 3 ms
5,376 KB
testcase_89 AC 3 ms
5,376 KB
testcase_90 AC 3 ms
5,376 KB
testcase_91 AC 3 ms
5,376 KB
testcase_92 AC 3 ms
5,376 KB
testcase_93 AC 3 ms
5,376 KB
testcase_94 AC 3 ms
5,376 KB
testcase_95 AC 2 ms
5,376 KB
testcase_96 AC 3 ms
5,376 KB
testcase_97 AC 3 ms
5,376 KB
testcase_98 AC 3 ms
5,376 KB
testcase_99 AC 3 ms
5,376 KB
testcase_100 AC 3 ms
5,376 KB
testcase_101 AC 3 ms
5,376 KB
testcase_102 AC 3 ms
5,376 KB
testcase_103 AC 3 ms
5,376 KB
testcase_104 AC 3 ms
5,376 KB
testcase_105 AC 3 ms
5,376 KB
testcase_106 AC 3 ms
5,376 KB
testcase_107 AC 3 ms
5,376 KB
testcase_108 AC 3 ms
5,376 KB
testcase_109 AC 3 ms
5,376 KB
testcase_110 AC 2 ms
5,376 KB
testcase_111 AC 3 ms
5,376 KB
testcase_112 AC 2 ms
5,376 KB
testcase_113 AC 2 ms
5,376 KB
testcase_114 AC 2 ms
5,376 KB
testcase_115 AC 2 ms
5,376 KB
testcase_116 AC 2 ms
5,376 KB
testcase_117 AC 2 ms
5,376 KB
testcase_118 AC 2 ms
5,376 KB
testcase_119 AC 2 ms
5,376 KB
testcase_120 AC 2 ms
5,376 KB
testcase_121 AC 2 ms
5,376 KB
testcase_122 AC 2 ms
5,376 KB
testcase_123 AC 2 ms
5,376 KB
testcase_124 AC 2 ms
5,376 KB
testcase_125 AC 2 ms
5,376 KB
testcase_126 AC 2 ms
5,376 KB
testcase_127 AC 2 ms
5,376 KB
testcase_128 AC 15 ms
5,376 KB
testcase_129 AC 42 ms
8,960 KB
testcase_130 AC 28 ms
7,296 KB
testcase_131 AC 50 ms
10,240 KB
testcase_132 AC 51 ms
10,112 KB
testcase_133 AC 2 ms
5,376 KB
testcase_134 AC 2 ms
5,376 KB
testcase_135 AC 16 ms
5,504 KB
testcase_136 AC 17 ms
5,504 KB
testcase_137 AC 3 ms
5,376 KB
testcase_138 AC 35 ms
8,064 KB
testcase_139 AC 42 ms
8,832 KB
testcase_140 AC 4 ms
6,144 KB
testcase_141 AC 56 ms
10,496 KB
testcase_142 AC 24 ms
6,272 KB
testcase_143 AC 3 ms
5,376 KB
testcase_144 AC 50 ms
9,600 KB
testcase_145 AC 4 ms
5,376 KB
testcase_146 AC 11 ms
5,376 KB
testcase_147 AC 38 ms
8,192 KB
testcase_148 AC 20 ms
5,888 KB
testcase_149 AC 32 ms
7,552 KB
testcase_150 AC 46 ms
9,344 KB
testcase_151 AC 4 ms
5,376 KB
testcase_152 AC 4 ms
5,376 KB
testcase_153 AC 4 ms
6,400 KB
testcase_154 AC 3 ms
5,376 KB
testcase_155 AC 41 ms
8,704 KB
testcase_156 AC 13 ms
5,376 KB
testcase_157 AC 41 ms
8,704 KB
testcase_158 AC 56 ms
10,752 KB
testcase_159 AC 8 ms
5,376 KB
testcase_160 AC 4 ms
5,376 KB
testcase_161 AC 47 ms
9,600 KB
testcase_162 AC 4 ms
6,144 KB
testcase_163 AC 3 ms
5,376 KB
testcase_164 AC 55 ms
10,624 KB
testcase_165 AC 42 ms
8,832 KB
testcase_166 AC 8 ms
5,376 KB
testcase_167 AC 27 ms
6,912 KB
testcase_168 AC 18 ms
5,504 KB
testcase_169 AC 20 ms
5,760 KB
testcase_170 AC 15 ms
5,376 KB
testcase_171 AC 27 ms
6,912 KB
testcase_172 AC 21 ms
6,144 KB
testcase_173 AC 6 ms
5,376 KB
testcase_174 AC 48 ms
9,600 KB
testcase_175 AC 63 ms
11,008 KB
testcase_176 AC 39 ms
8,448 KB
testcase_177 AC 6 ms
5,376 KB
testcase_178 AC 42 ms
8,704 KB
testcase_179 AC 46 ms
9,088 KB
testcase_180 AC 4 ms
6,016 KB
testcase_181 AC 2 ms
5,376 KB
testcase_182 AC 3 ms
5,376 KB
testcase_183 AC 4 ms
5,376 KB
testcase_184 AC 3 ms
5,376 KB
testcase_185 AC 4 ms
5,376 KB
testcase_186 AC 4 ms
5,760 KB
testcase_187 AC 3 ms
5,376 KB
testcase_188 AC 2 ms
5,376 KB
testcase_189 AC 2 ms
5,376 KB
testcase_190 AC 2 ms
5,376 KB
testcase_191 AC 2 ms
5,376 KB
testcase_192 AC 2 ms
5,376 KB
testcase_193 AC 2 ms
5,376 KB
testcase_194 AC 2 ms
5,376 KB
testcase_195 AC 2 ms
5,376 KB
testcase_196 AC 43 ms
7,936 KB
testcase_197 AC 11 ms
5,376 KB
testcase_198 AC 26 ms
6,784 KB
testcase_199 AC 39 ms
8,192 KB
testcase_200 AC 10 ms
5,760 KB
testcase_201 AC 7 ms
5,376 KB
testcase_202 AC 48 ms
8,960 KB
testcase_203 AC 23 ms
6,272 KB
testcase_204 AC 55 ms
10,496 KB
testcase_205 AC 26 ms
6,656 KB
testcase_206 AC 6 ms
6,272 KB
testcase_207 AC 12 ms
5,376 KB
testcase_208 AC 39 ms
8,320 KB
testcase_209 AC 12 ms
5,376 KB
testcase_210 AC 6 ms
5,376 KB
testcase_211 AC 17 ms
5,632 KB
testcase_212 AC 3 ms
5,376 KB
testcase_213 AC 9 ms
5,376 KB
testcase_214 AC 56 ms
10,752 KB
testcase_215 AC 45 ms
9,344 KB
testcase_216 AC 54 ms
10,368 KB
testcase_217 AC 28 ms
7,168 KB
testcase_218 AC 8 ms
6,144 KB
testcase_219 AC 4 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  auto ab2xy = [](long long a, long long b) {
    return make_pair((a + b) / 2, (b - a) / 2);
  };
  long long w, h;
  cin >> w >> h;
  int n;
  cin >> n;
  vector<long long> x(n), y(n), a(n), b(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
    --x[i], --y[i];
    a[i] = x[i] - y[i];
    b[i] = x[i] + y[i];
    if ((a[i] - a[0]) & 1) {
      cout << "0\n";
      return 0;
    }
  }
  if (n == 2) {
    if (x[0] > x[1]) {
      swap(x[0], x[1]);
      swap(y[0], y[1]);
    }
    if (y[0] > y[1]) {
      y[0] = h - y[0] - 1;
      y[1] = h - y[1] - 1;
    }
    long long res = 0;
    if (x[0] - y[0] == x[1] - y[1]) {
      res += x[1] - x[0] - 1;
      res += (w - x[1]) * (y[0] + 1);
      res += (x[0] + 1) * (h - y[1]);
    } else {
      if (x[1] - x[0] < y[1] - y[0]) {
        swap(w, h);
        swap(x[0], y[0]);
        swap(x[1], y[1]);
      }
      res += y[1] - y[0] - 1;
      res += y[0] + 1;
      res += h - y[1];
    }
    cout << res << '\n';
    return 0;
  }
  set<long long> sa(begin(a), end(a));
  set<long long> sb(begin(b), end(b));
  long long min_x = *min_element(begin(x), end(x));
  long long max_x = *max_element(begin(x), end(x));
  long long min_y = *min_element(begin(y), end(y));
  long long max_y = *max_element(begin(y), end(y));
  long long min_a = *begin(sa), max_a = *rbegin(sa);
  long long min_b = *begin(sb), max_b = *rbegin(sb);
  long long res = 0, add = 0;
  if (sa.size() == 1 or sb.size() == 1) {
    if (sa.size() == 1) {
      res += (w - max_x) * (min_y + 1);
      res += (min_x + 1) * (h - max_y);
    } else {
      res += (w - max_x) * (h - max_y);
      res += (min_x + 1) * (min_y + 1);
    }
  } else {
    for (int S = 0; S < 1 << 4; ++S) {
      bool ok = true;
      for (int i = 0; i < n; ++i) {
        if (a[i] == min_a and S >> 0 & 1) continue;
        if (a[i] == max_a and S >> 1 & 1) continue;
        if (b[i] == min_b and S >> 2 & 1) continue;
        if (b[i] == max_b and S >> 3 & 1) continue;
        ok = false;
        break;
      }
      if (ok) {
        int cnt = __builtin_popcount(S);
        if (cnt == 4) {
          res = max<long long>(res, max_a - min_a == max_b - min_b);
        } else if (cnt == 3) {
          if ((S & 3) != 3) {
            res = max<long long>(res, max_a - min_a <= max_b - min_b);
          } else {
            res = max<long long>(res, max_b - min_b <= max_a - min_a);
          }
        } else {
          assert(cnt == 2);
          long long da = max_a - min_a;
          assert(~da & 1);
          da /= 2;
          long long db = max_b - min_b;
          assert(~db & 1);
          db /= 2;
          long long len = max(da, db);
          if (S == 3) {
            // res = max<long long>(res, max(da - db + 1, 0LL));
            add += max(da - db, 0LL);
          } else if (S == 12) {
            // res = max<long long>(res, max(db - da + 1, 0LL));
            add += max(db - da, 0LL);
          } else if (S == 5) {
            res = max<long long>(res, w - ab2xy(min_a + len, min_b + len).first);
          } else if (S == 6) {
            res = max<long long>(res, h - ab2xy(max_a - len, min_b + len).second);
          } else if (S == 9) {
            res = max<long long>(res, ab2xy(min_a + len, max_b - len).second + 1);
          } else {
            res = max<long long>(res, ab2xy(max_a - len, max_b - len).first + 1);
          }
        }
        // cerr << S << ' ' << res << '\n';
      }
    }
  }
  res += add;
  cout << res << '\n';

  /*else if (sa.size() == 2 or sb.size() == 2) {
    assert(false);
    long long da = max_a - min_a;
    assert(~da & 1);
    da /= 2;
    long long db = max_b - min_b;
    assert(~db & 1);
    db /= 2;
    long long len = max(da, db);
    if (sa.size() == 2) {
      int cmin_a = count(begin(a), end(a), min_a);
      int cmax_a = count(begin(a), end(a), max_a);
      long long min_ab = b[min_element(begin(a), end(a)) - begin(a)];
      long long max_ab = b[max_element(begin(a), end(a)) - begin(a)];
      if (cmin_a == 1 and min_ab == min_b) {
        res += max(h - ab2xy(max_a - len, min_b + len).second, 0LL);
      } else if (cmin_a == 1 and min_ab == max_b) {
        res += min(ab2xy(max_a - len, max_b - len).first + 1, w);
      } else if (cmax_a == 1 and max_ab == min_b) {
        res += max(w - ab2xy(min_a + len, min_b + len).first, 0LL);
      } else if (cmax_a == 1 and max_ab == max_b) {
        res += min(ab2xy(min_a + len, max_b - len).second + 1, h);
      } else {
        res += max(da - db + 1, 0LL);
      }
    } else {
      int cmin_b = count(begin(b), end(b), min_b);
      int cmax_b = count(begin(b), end(b), max_b);
      long long min_ba = a[min_element(begin(b), end(b)) - begin(b)];
      long long max_ba = a[max_element(begin(b), end(b)) - begin(b)];
      if (cmin_b == 1 and min_ba == min_a) {
        res += min(ab2xy(min_a + len, max_b - len).second + 1, h);
      } else if (cmin_b == 1 and min_ba == max_a) {
        res += min(ab2xy(max_a - len, max_b - len).first + 1, w);
      } else if (cmax_b == 1 and max_ba == min_a) {
        res += max(w - ab2xy(min_a + len, min_b + len).first, 0LL);
      } else if (cmax_b == 1 and max_ba == max_a) {
        res += max(h - ab2xy(max_a - len, min_b + len).second, 0LL);
      } else {
        res += max(db - da + 1, 0LL);
      }
    }
  } else {
    for (int i = 0; i < n; ++i) {
      if (a[i] != min_a and a[i] != max_a and
          b[i] != min_b and b[i] != max_b) {
        cout << "0\n";
        return 0;
      }
    }
    set<long long> ta, tb;
    for (int i = 0; i < n; ++i) {
      if (a[i] != min_a and a[i] != max_a) {
        tb.insert(b[i]);
      }
      if (b[i] != min_b and b[i] != max_b) {
        ta.insert(a[i]);
      }
    }
    if (ta.size() == 2 and tb.size() == 2) {
      if (max_a - min_a != max_b - min_b) {
        res = 0;
      }
    } else if (ta.size() == 1 and tb.size() == 1) {

    }
    res = 1;
  }
  cout << res << '\n';*/
}
0