結果

問題 No.3601 Queen Dist Sum with One Wall
コンテスト
ユーザー askr58
提出日時 2026-07-25 00:01:45
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,435 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,110 ms
コンパイル使用メモリ 180,384 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-25 00:02:02
合計ジャッジ時間 6,475 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 9 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <deque>
#include <string>
#include <ranges>
#include <algorithm>
#include <vector>
using namespace std;
using ll=long long;
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int ttt;
	cin>>ttt;
	while(ttt--){
		ll h,w,a,b,x,y;
		cin>>h>>w>>a>>b>>x>>y;
		a--;b--;x--;y--;
		ll ans=h*w*2-4;
		auto f=[](ll w,ll x,ll y,ll z)->ll{
			//cout<<w<<" "<<x<<" "<<y<<" "<<z<<endl;
			ll l=max(y+1,x+z);
			ll res2=max(0ll,x+z-y)-1;
			ll r=max(l,min(w,2*z+x));
			ll res;
			if(x%2==0){
				if(l%2==0)res=(r-l+1)/2;
				else res=(r-l)/2;
			}else{
				if(l%2==0)res=(r-l)/2;
				else res=(r-l+1)/2;
			}

			//cout<<res<<endl;
			return w-y-1-res-res2;
			//return 0;
		};
		if(b!=y){
			ans-=h-1;
		}else{
			if(a<x){
				ans-=a;
				ans-=x-a-1;
				ans+=f(h,a,x,max(w-b,b+1));
			}else{
				ans-=h-a-1;
				ans-=a-x-1;
				ans+=f(h,h-a-1,h-x-1,max(w-b,b+1));
			}
		}
		if(a!=x){
			ans-=w-1;
		}else{
			if(b<y){
				ans-=b;
				ans-=y-b-1;
				ans+=f(w,b,y,max(h-a,a+1));
			}else{
				ans-=w-b-1;
				ans-=b-y-1;
				ans+=f(w,w-b-1,w-y-1,max(h-a,a+1));
			}
		}
		if(a+b!=x+y){
			ans-=min(b,h-a-1)+min(a,w-b-1);
		}else if(a<x){
			ans-=x-a-1;
			ans-=min(b,h-a-1);
		}else{
			ans-=a-x-1;
			ans-=min(a,w-b-1);
		}
		if(a-b!=x-y){
			ans-=min(a,b)+min(w-b-1,h-a-1);
		}else if(a<x){
			ans-=x-a-1;
			ans-=min(a,b);
		}else{
			ans-=a-x-1;
			ans-=min(w-b-1,h-a-1);
		}
		cout<<ans<<endl;
	}
}


0