結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー 沙耶花沙耶花
提出日時 2022-05-20 21:54:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 151 ms / 3,000 ms
コード長 1,066 bytes
コンパイル時間 4,259 ms
コンパイル使用メモリ 259,040 KB
最終ジャッジ日時 2025-01-29 10:31:28
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001


int main() {
    
	int h,w,x,y;
	cin>>h>>w>>x>>y;
	x--,y--;
	
	vector<vector<int>> a(h,vector<int>(w));
	rep(i,h){
		rep(j,w)cin>>a[i][j];
	}
	
	long long c = a[x][y];
	a[x][y] = 0;
	vector f(h,vector<bool>(w,false));
	f[x][y] = true;
	priority_queue<pair<long long,pair<int,int>>,vector<pair<long long,pair<int,int>>>,greater<pair<long long,pair<int,int>>>> Q;
	Q.emplace(a[x][y],make_pair(x,y));
	vector<int> dx = {1,-1,0,0},dy = {0,0,1,-1};
	while(Q.size()>0){
		long long D = Q.top().first;
		x = Q.top().second.first;
		y = Q.top().second.second;
		if(D>=c)break;
		Q.pop();
		c += D;
		//cout<<c<<endl;
		rep(i,4){
			int xx = x+dx[i],yy = y+dy[i];
			if(xx<0||xx>=h||yy<0||yy>=w)continue;
			if(f[xx][yy])continue;
			Q.emplace(a[xx][yy],make_pair(xx,yy));
			f[xx][yy] = true;
		}
	}
	if(Q.size()>0)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
		
	
    return 0;
}
0