結果

問題 No.3599 Queen Moving Query
コンテスト
ユーザー askr58
提出日時 2026-07-24 22:11:05
言語 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,321 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,395 ms
コンパイル使用メモリ 199,176 KB
実行使用メモリ 21,888 KB
最終ジャッジ日時 2026-07-24 22:11:12
合計ジャッジ時間 6,646 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other WA * 26
権限があれば一括ダウンロードができます

ソースコード

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 h,w;
	cin>>h>>w;
	int sx,sy;
	cin>>sx>>sy;
	sx--;sy--;
	vector<string> s(h);
	for(int i=0;i<h;i++)cin>>s[i];
	vector<int> dx={1,0,-1,0,1,1,-1,-1},dy={0,1,0,-1,1,-1,1,-1};
	vector dist(17,vector(h,vector<int>(w,2e9)));
	dist[0][sx][sy]=0;
	deque<array<int,4>> deq;
	deq.push_back({0,0,sx,sy});
	while(!deq.empty()){
		auto[d,c,x,y]=deq.front();
		deq.pop_front();
		if(d>dist[c][x][y])continue;
		for(int r=0;r<8;r++){
			int nx=x+dx[r],ny=y+dy[r];
			if(nx<0||nx>=h||ny<0||ny>=w||s[nx][ny]=='#')continue;
			int w=0;
			if(c==0||(c-1)%8!=r)w=1;
			int nc;
			if(c>=9)nc=9+r;
			else if(c==0)nc=1+r;
			else if(c-1==r)nc=9+r;
			else nc=1+r;
			if(dist[nc][nx][ny]<=d+w)continue;
			dist[nc][nx][ny]=d+w;
			if(w==0)deq.push_front({d,nc,nx,ny});
			else deq.push_back({d+1,nc,nx,ny});
		}
	}
	int q;
	cin>>q;
	cout<<endl;
	while(q--){
		int gx,gy,t;
		cin>>gx>>gy>>t;
		gx--;gy--;
		bool ok=false;
		for(int i=1;i<=16;i++){
			if(i<=8&&dist[i][gx][gy]<=t&&(t-dist[i][gx][gy])%2==0)ok=true;
			if(i>=9&&dist[i][gx][gy]<=t)ok=true;
		}
		if(ok)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}

		

			
		
0