結果

問題 No.960 マンハッタン距離3
ユーザー PachicobuePachicobue
提出日時 2019-12-23 03:13:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 11,172 bytes
コンパイル時間 2,441 ms
コンパイル使用メモリ 221,232 KB
実行使用メモリ 17,312 KB
最終ジャッジ日時 2024-09-15 01:50:19
合計ジャッジ時間 18,120 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 3 ms
5,376 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 RE -
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 RE -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
5,376 KB
testcase_27 WA -
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 2 ms
5,376 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 2 ms
5,376 KB
testcase_36 WA -
testcase_37 RE -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 2 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 2 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 2 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 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
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 RE -
testcase_68 AC 3 ms
5,376 KB
testcase_69 AC 3 ms
5,376 KB
testcase_70 AC 4 ms
5,376 KB
testcase_71 AC 3 ms
5,376 KB
testcase_72 AC 3 ms
5,376 KB
testcase_73 AC 4 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 3 ms
5,376 KB
testcase_78 AC 3 ms
5,376 KB
testcase_79 AC 2 ms
5,376 KB
testcase_80 RE -
testcase_81 RE -
testcase_82 AC 3 ms
5,376 KB
testcase_83 AC 3 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 RE -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 AC 2 ms
5,376 KB
testcase_93 AC 2 ms
5,376 KB
testcase_94 WA -
testcase_95 WA -
testcase_96 WA -
testcase_97 WA -
testcase_98 AC 2 ms
5,376 KB
testcase_99 AC 2 ms
5,376 KB
testcase_100 WA -
testcase_101 WA -
testcase_102 WA -
testcase_103 RE -
testcase_104 AC 2 ms
5,376 KB
testcase_105 AC 2 ms
5,376 KB
testcase_106 RE -
testcase_107 WA -
testcase_108 WA -
testcase_109 WA -
testcase_110 AC 2 ms
5,376 KB
testcase_111 AC 2 ms
5,376 KB
testcase_112 RE -
testcase_113 RE -
testcase_114 RE -
testcase_115 RE -
testcase_116 RE -
testcase_117 RE -
testcase_118 AC 2 ms
5,376 KB
testcase_119 AC 2 ms
5,376 KB
testcase_120 RE -
testcase_121 AC 2 ms
5,376 KB
testcase_122 AC 2 ms
5,376 KB
testcase_123 RE -
testcase_124 RE -
testcase_125 AC 2 ms
5,376 KB
testcase_126 AC 2 ms
5,376 KB
testcase_127 RE -
testcase_128 TLE -
testcase_129 AC 764 ms
6,272 KB
testcase_130 TLE -
testcase_131 -- -
testcase_132 -- -
testcase_133 -- -
testcase_134 -- -
testcase_135 -- -
testcase_136 -- -
testcase_137 -- -
testcase_138 -- -
testcase_139 -- -
testcase_140 -- -
testcase_141 -- -
testcase_142 -- -
testcase_143 -- -
testcase_144 -- -
testcase_145 -- -
testcase_146 -- -
testcase_147 -- -
testcase_148 -- -
testcase_149 -- -
testcase_150 -- -
testcase_151 -- -
testcase_152 -- -
testcase_153 -- -
testcase_154 -- -
testcase_155 -- -
testcase_156 -- -
testcase_157 -- -
testcase_158 -- -
testcase_159 -- -
testcase_160 -- -
testcase_161 -- -
testcase_162 -- -
testcase_163 -- -
testcase_164 -- -
testcase_165 -- -
testcase_166 -- -
testcase_167 -- -
testcase_168 -- -
testcase_169 -- -
testcase_170 -- -
testcase_171 -- -
testcase_172 -- -
testcase_173 -- -
testcase_174 -- -
testcase_175 -- -
testcase_176 -- -
testcase_177 -- -
testcase_178 -- -
testcase_179 -- -
testcase_180 -- -
testcase_181 -- -
testcase_182 -- -
testcase_183 -- -
testcase_184 -- -
testcase_185 -- -
testcase_186 -- -
testcase_187 -- -
testcase_188 -- -
testcase_189 -- -
testcase_190 -- -
testcase_191 -- -
testcase_192 -- -
testcase_193 -- -
testcase_194 -- -
testcase_195 -- -
testcase_196 -- -
testcase_197 -- -
testcase_198 -- -
testcase_199 -- -
testcase_200 -- -
testcase_201 -- -
testcase_202 -- -
testcase_203 -- -
testcase_204 -- -
testcase_205 -- -
testcase_206 -- -
testcase_207 -- -
testcase_208 -- -
testcase_209 -- -
testcase_210 -- -
testcase_211 -- -
testcase_212 -- -
testcase_213 -- -
testcase_214 -- -
testcase_215 -- -
testcase_216 -- -
testcase_217 -- -
testcase_218 -- -
testcase_219 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// created [2019/12/23] 00:51:38
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wsign-conversion"

using i32   = int32_t;
using i64   = int64_t;
using u32   = uint32_t;
using u64   = uint64_t;
using uint  = unsigned int;
using usize = std::size_t;
using ll    = long long;
using ull   = unsigned long long;
using ld    = long double;
template<typename T, usize n>
using arr = T (&)[n];
template<typename T, usize n>
using c_arr = const T (&)[n];
template<typename T> constexpr T popcount(const T u) { return u ? static_cast<T>(__builtin_popcountll(static_cast<u64>(u))) : static_cast<T>(0); }
template<typename T> constexpr T log2p1(const T u) { return u ? static_cast<T>(64 - __builtin_clzll(static_cast<u64>(u))) : static_cast<T>(0); }
template<typename T> constexpr T msbp1(const T u) { return log2p1(u); }
template<typename T> constexpr T lsbp1(const T u) { return __builtin_ffsll(u); }
template<typename T> constexpr T clog(const T u) { return u ? log2p1(u - 1) : static_cast<T>(u); }
template<typename T> constexpr bool ispow2(const T u) { return u and (static_cast<u64>(u) & static_cast<u64>(u - 1)) == 0; }
template<typename T> constexpr T ceil2(const T u) { return static_cast<T>(1) << clog(u); }
template<typename T> constexpr T floor2(const T u) { return u == 0 ? static_cast<T>(0) : static_cast<T>(1) << (log2p1(u) - 1); }
template<typename T> constexpr bool btest(const T mask, const usize ind) { return static_cast<bool>((static_cast<u64>(mask) >> ind) & static_cast<u64>(1)); }
template<typename T> void bset(T& mask, const usize ind) { mask |= (static_cast<T>(1) << ind); }
template<typename T> void breset(T& mask, const usize ind) { mask &= ~(static_cast<T>(1) << ind); }
template<typename T> void bflip(T& mask, const usize ind) { mask ^= (static_cast<T>(1) << ind); }
template<typename T> void bset(T& mask, const usize ind, const bool b) { (b ? bset(mask, ind) : breset(mask, ind)); }
template<typename T> constexpr T bcut(const T mask, const usize ind) { return ind == 0 ? static_cast<T>(0) : static_cast<T>((static_cast<u64>(mask) << (64 - ind)) >> (64 - ind)); }
template<typename T> bool chmin(T& a, const T& b) { return (a > b ? a = b, true : false); }
template<typename T> bool chmax(T& a, const T& b) { return (a < b ? a = b, true : false); }
constexpr unsigned int mod                  = 1000000007;
template<typename T> constexpr T inf_v      = std::numeric_limits<T>::max() / 4;
template<typename Real> constexpr Real pi_v = Real{3.141592653589793238462643383279502884};
auto mfp = [](auto&& f) { return [=](auto&&... args) { return f(f, std::forward<decltype(args)>(args)...); }; };

template<typename T>
T in()
{
    T v;
    return std::cin >> v, v;
}
template<typename T, typename Uint, usize n, usize i>
T in_v(typename std::enable_if<(i == n), c_arr<Uint, n>>::type) { return in<T>(); }
template<typename T, typename Uint, usize n, usize i>
auto in_v(typename std::enable_if<(i < n), c_arr<Uint, n>>::type& szs)
{
    const usize s = (usize)szs[i];
    std::vector<decltype(in_v<T, Uint, n, i + 1>(szs))> ans(s);
    for (usize j = 0; j < s; j++) { ans[j] = in_v<T, Uint, n, i + 1>(szs); }
    return ans;
}
template<typename T, typename Uint, usize n>
auto in_v(c_arr<Uint, n> szs) { return in_v<T, Uint, n, 0>(szs); }
template<typename... Types>
auto in_t() { return std::tuple<std::decay_t<Types>...>{in<Types>()...}; }
struct io_init
{
    io_init()
    {
        std::cin.tie(nullptr), std::ios::sync_with_stdio(false);
        std::cout << std::fixed << std::setprecision(20);
    }
    void clear()
    {
        std::cin.tie(), std::ios::sync_with_stdio(true);
    }
} io_setting;

template<typename T>
int out(const T& v) { return std::cout << v, 0; }
template<typename T>
int out(const std::vector<T>& v)
{
    for (usize i = 0; i < v.size(); i++) {
        if (i > 0) { std::cout << ' '; }
        out(v[i]);
    }
    return std::cout << "\n", 0;
}
template<typename T1, typename T2>
int out(const std::pair<T1, T2>& v) { return out(v.first), std::cout << ' ', out(v.second), 0; }
template<typename T, typename... Args>
int out(const T& v, const Args... args) { return out(v), std::cout << ' ', out(args...), 0; }
template<typename... Args>
int outln(const Args... args) { return out(args...), std::cout << '\n', 0; }
template<typename... Args>
void outel(const Args... args) { return out(args...), std::cout << std::endl, 0; }
#    define SHOW(...) static_cast<void>(0)
constexpr ull TEN(const usize n) { return n == 0 ? 1ULL : TEN(n - 1) * 10ULL; }

template<typename T, typename Uint, usize n, usize i>
auto make_v(typename std::enable_if<(i == n), c_arr<Uint, n>>::type, const T& v = T{}) { return v; }
template<typename T, typename Uint, usize n, usize i>
auto make_v(typename std::enable_if<(i < n), c_arr<Uint, n>>::type szs, const T& v = T{})
{
    const usize s = (usize)szs[i];
    return std::vector<decltype(make_v<T, Uint, n, i + 1>(szs, v))>(s, make_v<T, Uint, n, i + 1>(szs, v));
}
template<typename T, typename Uint, usize n>
auto make_v(c_arr<Uint, n> szs, const T& t = T{}) { return make_v<T, Uint, n, 0>(szs, t); }
int main()
{
    auto L1   = [&](const ll x1, const ll y1, const ll x2, const ll y2) { return std::abs(x1 - x2) + std::abs(y1 - y2); };
    auto Linf = [&](const ll x1, const ll y1, const ll x2, const ll y2) { return std::max(std::abs(x1 - x2), std::abs(y1 - y2)); };
    auto W = in<ll>(), H = in<ll>();
    const auto N = in<int>();
    std::vector<ll> rxs(N), rys(N);
    for (int i = 0; i < N; i++) { rxs[i] = in<ll>(), rys[i] = in<ll>(); }
    {
        std::set<int> mod;
        for (int i = 0; i < N; i++) { mod.insert(L1(rxs[i], rys[i], 0, 0) % 2); }
        if (mod.size() == 2) { return outln(0); }
    }
    if (N <= 12) {
        assert(false);
        // やる
    }
    std::vector<ll> xs(N), ys(N);
    auto make = [&]() { for (int i = 0; i < N; i++) { xs[i] = rxs[i] + rys[i], ys[i] = rxs[i] - rys[i]; } };
    make();
    auto flip  = [&]() { std::swap(W, H), std::swap(rxs, rys), make(); };
    auto xflip = [&]() {
        for (int i = 0; i < N; i++) { rxs[i] = W + 1 - rxs[i]; }
        make();
    };
    auto solve = [&]() -> bool {
        std::map<ll, std::vector<int>> xis;
        for (int i = 0; i < N; i++) { xis[xs[i]].push_back(i); }
        ll vx = -1;  // 縦に3点乗っている直線
        for (int x = 0; x <= W + H; x++) {
            if (not xis.count(x)) { continue; }
            if (xis[x].size() >= 3) { vx = x; }
        }
        if (vx == -1) { return false; }
        if (xis[vx].size() == N) {
            ll rxmin = inf_v<ll>, rxmax = -inf_v<ll>;
            ll rymin = inf_v<ll>, rymax = -inf_v<ll>;
            for (const int i : xis[vx]) {
                chmin(rxmin, rxs[i]), chmax(rxmax, rxs[i]);
                chmin(rymin, rys[i]), chmax(rymax, rys[i]);
            }
            outln(rxmin * rymin + (W - rxmax + 1) * (H - rymax + 1));
            return true;
        }

        ll oi = -1;  // 外の点
        for (ll x = vx + 1; x <= W; x++) {
            if (xis.count(x)) { oi = xis[x][0]; }
        }
        if (oi == -1) {
            xflip();
            vx = W + 1 - vx;
            xis.clear();
            for (int i = 0; i < N; i++) { xis[xs[i]].push_back(i); }
            for (ll x = vx + 1; x <= W; x++) {
                if (xis.count(x)) { oi = xis[x][0]; }
            }
        }
        ll vymin = inf_v<ll>, vymax = -inf_v<ll>;
        for (const int i : xis[vx]) { chmin(vymin, ys[i]), chmax(vymax, rys[i]); }
        const ll oy = ys[oi], ox = xs[oi];
        if (vymin < oy and oy < vymax) { return false; }
        ll cy = 0, cx = 0;  // 中心の乗る半直線の開始地点
        if (oy >= vymax) {
            cy = vymin + oy, cx = vx + oy - vymin;
            if (cy % 2 == 1 or cx % 2 == 1) { return false; }
            cy /= 2, cx /= 2;
            // 半直線は(cx,cy)から(1,-1)方向
            const ll y_x = cy - cx;
            ll d_above = -1, d_below = -1;
            for (int i = 0; i < N; i++) {
                bool above = (ys[i] - xs[i]) >= y_x;
                const ll d = Linf(xs[i], ys[i], cx, cy);
                if (above) {
                    if (d_above != -1 and d_above != d) { return false; }
                    d_above = d;
                } else {
                    if (d_below != -1 and d_below != d) { return false; }
                    d_below = d;
                }
            }
            if (d_above == -1) { return false; }
            if (d_below == -1) {
                ll p = cx + cy, q = cx - cy;
                if (p % 2 == 1 or q % 2 == 1) { return false; }
                p /= 2, q /= 2;
                if (p < 1 or W < p) { return false; }
                if (q < 1 or H < q) { return false; }
                outln(H - q + 1);
                return true;
            } else {
                if (d_above > d_below) { return false; }
                ll l = d_below - d_above;
                if (l % 2 == 1) { return false; }
                l /= 2;
                const ll x = cx + l, y = cy - l;
                ll p = x + y, q = x - y;
                if (p % 2 == 1 or q % 2 == 1) { return false; }
                if (p < 1 or W < p) { return false; }
                if (q < 1 or H < q) { return false; }
                outln(1);
                return true;
            }
        } else {
            cy = vymax + oy, cx = vx + vymax - oy;
            if (cy % 2 == 1 or cx % 2 == 1) { return false; }
            cy /= 2, cx /= 2;
            // 半直線は(cx,cy)から(1,1)方向
            const ll y_x = cy + cx;
            ll d_above = -1, d_below = -1;
            for (int i = 0; i < N; i++) {
                bool above = (ys[i] + xs[i]) <= y_x;
                const ll d = Linf(xs[i], ys[i], cx, cy);
                if (above) {
                    if (d_above != -1 and d_above != d) { return false; }
                    d_above = d;
                } else {
                    if (d_below != -1 and d_below != d) { return false; }
                    d_below = d;
                }
            }
            if (d_above == -1) { return false; }
            if (d_below == -1) {
                ll p = cx + cy, q = cx - cy;
                if (p % 2 == 1 or q % 2 == 1) { return false; }
                p /= 2, q /= 2;
                if (p < 1 or W < p) { return false; }
                if (q < 1 or H < q) { return false; }
                outln(W - p + 1);
                return true;
            } else {
                if (d_above > d_below) { return false; }
                ll l = d_below - d_above;
                if (l % 2 == 1) { return false; }
                l /= 2;
                const ll x = cx + l, y = cy + l;
                ll p = x + y, q = x - y;
                if (p % 2 == 1 or q % 2 == 1) { return false; }
                if (p < 1 or W < p) { return false; }
                if (q < 1 or H < q) { return false; }
                outln(1);
                return true;
            }
        }
    };
    if (not solve()) {
        flip();
        if (not solve()) { return outln(0); }
    }

    return 0;
}
0