結果

問題 No.960 マンハッタン距離3
ユーザー risujirohrisujiroh
提出日時 2019-12-23 01:50:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,741 bytes
コンパイル時間 1,644 ms
コンパイル使用メモリ 173,920 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-14 23:24:01
合計ジャッジ時間 23,867 ms
ジャッジサーバーID
(参考情報)
judge6 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 2 ms
5,376 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 2 ms
5,376 KB
testcase_30 RE -
testcase_31 RE -
testcase_32 AC 2 ms
5,376 KB
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 2 ms
5,376 KB
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 AC 2 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
testcase_69 RE -
testcase_70 RE -
testcase_71 RE -
testcase_72 AC 2 ms
5,376 KB
testcase_73 AC 2 ms
5,376 KB
testcase_74 AC 2 ms
5,376 KB
testcase_75 AC 2 ms
5,376 KB
testcase_76 AC 2 ms
5,376 KB
testcase_77 AC 2 ms
5,376 KB
testcase_78 AC 2 ms
5,376 KB
testcase_79 AC 2 ms
5,376 KB
testcase_80 AC 2 ms
5,376 KB
testcase_81 AC 2 ms
5,376 KB
testcase_82 AC 2 ms
5,376 KB
testcase_83 AC 2 ms
5,376 KB
testcase_84 AC 2 ms
5,376 KB
testcase_85 AC 2 ms
5,376 KB
testcase_86 AC 2 ms
5,376 KB
testcase_87 AC 2 ms
5,376 KB
testcase_88 RE -
testcase_89 RE -
testcase_90 RE -
testcase_91 RE -
testcase_92 AC 2 ms
5,376 KB
testcase_93 AC 2 ms
5,376 KB
testcase_94 RE -
testcase_95 RE -
testcase_96 RE -
testcase_97 RE -
testcase_98 AC 2 ms
5,376 KB
testcase_99 AC 2 ms
5,376 KB
testcase_100 RE -
testcase_101 RE -
testcase_102 RE -
testcase_103 AC 2 ms
5,376 KB
testcase_104 AC 2 ms
5,376 KB
testcase_105 AC 2 ms
5,376 KB
testcase_106 RE -
testcase_107 RE -
testcase_108 RE -
testcase_109 RE -
testcase_110 AC 2 ms
5,376 KB
testcase_111 AC 2 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 RE -
testcase_129 RE -
testcase_130 RE -
testcase_131 RE -
testcase_132 RE -
testcase_133 RE -
testcase_134 AC 2 ms
5,376 KB
testcase_135 RE -
testcase_136 RE -
testcase_137 AC 3 ms
5,376 KB
testcase_138 RE -
testcase_139 RE -
testcase_140 AC 5 ms
6,272 KB
testcase_141 RE -
testcase_142 RE -
testcase_143 AC 4 ms
5,376 KB
testcase_144 RE -
testcase_145 RE -
testcase_146 RE -
testcase_147 RE -
testcase_148 RE -
testcase_149 RE -
testcase_150 RE -
testcase_151 RE -
testcase_152 AC 4 ms
5,376 KB
testcase_153 AC 4 ms
6,400 KB
testcase_154 RE -
testcase_155 RE -
testcase_156 RE -
testcase_157 RE -
testcase_158 RE -
testcase_159 RE -
testcase_160 RE -
testcase_161 RE -
testcase_162 AC 4 ms
6,016 KB
testcase_163 AC 3 ms
5,376 KB
testcase_164 RE -
testcase_165 RE -
testcase_166 RE -
testcase_167 RE -
testcase_168 RE -
testcase_169 RE -
testcase_170 RE -
testcase_171 RE -
testcase_172 RE -
testcase_173 RE -
testcase_174 RE -
testcase_175 RE -
testcase_176 RE -
testcase_177 RE -
testcase_178 RE -
testcase_179 RE -
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 3 ms
5,376 KB
testcase_184 AC 3 ms
5,376 KB
testcase_185 AC 3 ms
5,376 KB
testcase_186 AC 4 ms
5,760 KB
testcase_187 AC 4 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 RE -
testcase_197 RE -
testcase_198 RE -
testcase_199 RE -
testcase_200 AC 10 ms
5,760 KB
testcase_201 AC 7 ms
5,376 KB
testcase_202 RE -
testcase_203 RE -
testcase_204 RE -
testcase_205 RE -
testcase_206 AC 5 ms
6,144 KB
testcase_207 AC 13 ms
5,376 KB
testcase_208 RE -
testcase_209 RE -
testcase_210 RE -
testcase_211 RE -
testcase_212 AC 3 ms
5,376 KB
testcase_213 AC 10 ms
5,376 KB
testcase_214 RE -
testcase_215 RE -
testcase_216 RE -
testcase_217 RE -
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;
  }
  assert(false);
  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;
  if (sa.size() == 1 or sb.size() == 1) {
    res += (w - max_x) * (min_y + 1);
    res += (min_x + 1) * (h - max_y);
  } 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 {
    assert(false);
    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;
      }
    }
    res = 1;
  }
  cout << res << '\n';
}
0