結果
| 問題 | No.3601 Queen Dist Sum with One Wall |
| コンテスト | |
| ユーザー |
Rubikun
|
| 提出日時 | 2026-07-24 22:25:28 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 33 ms / 2,000 ms |
| + 230µs | |
| コード長 | 2,502 bytes |
| 記録 | |
| コンパイル時間 | 1,106 ms |
| コンパイル使用メモリ | 210,560 KB |
| 実行使用メモリ | 5,888 KB |
| 最終ジャッジ日時 | 2026-07-24 22:25:43 |
| 合計ジャッジ時間 | 5,007 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;
ll f(ll x,ll y){
ll res=0;
res+=min(x,y);
res+=min(x/2,y);
res-=min(x/2,y/2);
return res;
ll res2=0;
for(ll i=1;i<=x;i++){
if(i<=y||(i%2==0&&i<=y+y)) res2++;
}
assert(res==res2);
return res;
}
ll solve(ll H,ll W,ll a,ll b,ll c,ll d){
ll ans=0;
ll al=H*W-1;
if(b==d){
swap(H,W);
swap(a,b);
swap(c,d);
}
if(a>c){
a=H+1-a;
c=H+1-c;
}
if(b>d){
b=W+1-b;
d=W+1-d;
}
a--;b--;c--;d--;
if(a!=c){
ll ONE=0;
ONE+=H-1;
ONE+=W-1;
ONE+=min(a,b);
if(a-b==c-d){
ONE+=c-a-1;
}else{
ONE+=min(H-1-a,W-1-b);
}
ONE+=min(a,W-1-b);
ONE+=min(H-1-a,b);
ans=ONE+(al-1-ONE)*2;
}else{
if(a<H-1-a){
a=H-1-a;
c=H-1-c;
}
ll ONE=0;
ONE+=H-1;
ONE+=b;
ONE+=d-b-1;
ONE+=min(a,b);
ONE+=min(H-1-a,W-1-b);
ONE+=min(a,W-1-b);
ONE+=min(H-1-a,b);
ll THREE=0;
THREE+=f(W-1-b,a);
THREE-=f(d-b,a);
THREE=W-1-d-THREE;
ll TWO=(al-1-ONE-THREE);
ans+=ONE;
ans+=TWO*2;
ans+=THREE*3;
}
return ans;
}
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int Q;cin>>Q;
while(Q--){
int H,W,a,b,c,d;cin>>H>>W>>a>>b>>c>>d;
cout<<solve(H,W,a,b,c,d)<<"\n";
}
}
Rubikun