結果
| 問題 | No.3601 Queen Dist Sum with One Wall |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-24 21:50:32 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 2,000 ms |
| + 552µs | |
| コード長 | 2,269 bytes |
| 記録 | |
| コンパイル時間 | 1,983 ms |
| コンパイル使用メモリ | 333,120 KB |
| 実行使用メモリ | 5,888 KB |
| 最終ジャッジ日時 | 2026-07-24 21:52:15 |
| 合計ジャッジ時間 | 6,253 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using vi=vector<int>;
using vl=vector<ll>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T>using pqg=priority_queue<T,vector<T>,greater<T>>;
#define all(x) begin(x),end(x)
#define rall(x) rbegin(x),rend(x)
#define sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
const ll INF=4e18;
const int MOD=1e9+7;
const int MOD2=998244353;
ll sign(ll x) { return (x > 0) - (x < 0); }
void solve(){
ll H, W, h, w, x, y;
cin >> H >> W >> h >> w >> x >> y;
ll n = H * W - 1;
ll c1 = 0;
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
rep(i, 0, 8) {
ll L = INF;
if (dx[i] == 1) L = min(L, H - h);
if (dx[i] == -1) L = min(L, h - 1);
if (dy[i] == 1) L = min(L, W - w);
if (dy[i] == -1) L = min(L, w - 1);
bool f = 0;
ll d_w = 0;
if (dx[i] == 0) {
if (x == h && sign(y - w) == dy[i]) { f = 1; d_w = abs(y - w); }
} else if (dy[i] == 0) {
if (y == w && sign(x - h) == dx[i]) { f = 1; d_w = abs(x - h); }
} else {
if (abs(x - h) == abs(y - w) && sign(x - h) == dx[i] && sign(y - w) == dy[i]) {
f = 1; d_w = abs(x - h);
}
}
if (f) c1 += d_w - 1;
else c1 += L;
}
ll c3 = 0;
auto get_c3 = [&](ll l, ll r, ll M) {
if (l > r) return 0LL;
ll res = 0;
ll l2 = max(l, M + 1), r2 = min(r, 2 * M);
if (l2 <= r2) res += (r2 + 1) / 2 - l2 / 2;
ll l3 = max(l, 2 * M + 1);
if (l3 <= r) res += r - l3 + 1;
return res;
};
if (x == h && y > w) c3 = get_c3(y - w + 1, W - w, max(H - h, h - 1));
else if (x == h && y < w) c3 = get_c3(w - y + 1, w - 1, max(H - h, h - 1));
else if (y == w && x > h) c3 = get_c3(x - h + 1, H - h, max(W - w, w - 1));
else if (y == w && x < h) c3 = get_c3(h - x + 1, h - 1, max(W - w, w - 1));
cout << 2 * n - 2 - c1 + c3 << "\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
if(cin >> t) while(t--) solve();
}