結果
| 問題 |
No.960 マンハッタン距離3
|
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2019-12-23 04:42:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,052 bytes |
| コンパイル時間 | 1,969 ms |
| コンパイル使用メモリ | 179,840 KB |
| 実行使用メモリ | 6,912 KB |
| 最終ジャッジ日時 | 2024-09-15 04:08:28 |
| 合計ジャッジ時間 | 11,944 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 199 WA * 17 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l) ; i < (r); ++i)
#define incII(i, l, r) for(int i = (l) ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r) ; i >= (l); --i)
#define inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) < (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin = [](auto & a, auto b) { return (b < a ? a = b, true : false); };
auto setmax = [](auto & a, auto b) { return (b > a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
// ----
#define inCI(v, l, r) ((l) < (v) && (v) <= (r))
#define inCD(v, l, r) ((l) < (v) && (v) < (r))
#define T0(T) T
#define T1(T) vector<T0(T)>
#define T2(T) vector<T1(T)>
#define V0(v, T ...) v
#define V1(v, T, n, ...) T1(T)(n, V0(v, T, __VA_ARGS__))
#define V2(v, T, n, ...) T2(T)(n, V1(v, T, __VA_ARGS__))
int main() {
LL h, w, n;
cin >> h >> w >> n;
vector<LL> a(n), b(n);
set<int> parity;
inc(i, n) {
LL x, y;
cin >> x >> y;
a[i] = x - y;
b[i] = x + y;
parity.insert((x + y) % 2);
}
auto solve = [&]() -> LL {
if(SI(parity) == 2) { return 0; }
LL INF = 1e12;
LL s = +INF, S = -INF;
LL t = +INF, T = -INF;
inc(i, n) {
setmin(s, a[i]);
setmax(S, a[i]);
setmin(t, b[i]);
setmax(T, b[i]);
}
inc(i, n) {
if(inCD(a[i], s, S) && inCD(b[i], t, T)) { return 0; }
}
auto xy = [](LL a, LL b) -> pair<LL, LL> {
assert((a + b) % 2 == 0);
return { (b + a) / 2, (b - a) / 2 };
};
auto st = xy(s, t);
auto sT = xy(s, T);
auto St = xy(S, t);
auto ST = xy(S, T);
if(s == S && t == T) { return h * w; }
if(s == S) {
LL x = st.FI, y = st.SE;
LL X = ST.FI, Y = ST.SE;
X = h + 1 - X;
Y = w + 1 - Y;
return x * y + X * Y + (n == 2 ? S - s - 1 : 0);
}
if(t == T) {
LL x = st.FI, Y = st.SE;
LL X = ST.FI, y = ST.SE;
X = h + 1 - X;
Y = w + 1 - Y;
return x * Y + X * y + (n == 2 ? T - t - 1 : 0);
}
auto ok = [&](LL x, LL y) -> bool {
set<LL> d;
inc(i, n) {
auto p = xy(a[i], b[i]);
d.insert(abs(x - p.FI) + abs(y - p.SE));
}
return (SI(d) == 1);
};
LL A = S - s, B = T - t, ans = 0;
if(A >= B) {
LL x = sT.FI, y = ST.SE;
LL X = St.FI, Y = st.SE;
if(ok(x, y)) { ans += 1; }
if(ok(X, Y) && A != B) { ans += 1; }
if(ok(x + 1, y + 1) && A != B) { ans += X - x - 1; }
if(ok(x - 1, y)) { ans += x - 1; }
if(ok(x, y - 1)) { ans += y - 1; }
if(ok(X + 1, Y)) { ans += h - X; }
if(ok(X, Y + 1)) { ans += w - Y; }
} else {
LL x = St.FI, y = st.SE;
LL X = sT.FI, Y = ST.SE;
if(ok(x, Y)) { ans += 1; }
if(ok(X, y)) { ans += 1; }
if(ok(x + 1, Y - 1)) { ans += X - x - 1; }
if(ok(x - 1, Y)) { ans += x - 1; }
if(ok(X, y - 1)) { ans += y - 1; }
if(ok(X + 1, y)) { ans += h - X; }
if(ok(x, Y + 1)) { ans += w - Y; }
}
return ans;
};
cout << solve() << endl;
return 0;
}
FF256grhy