結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー 沙耶花沙耶花
提出日時 2022-05-20 21:54:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 144 ms / 3,000 ms
コード長 1,066 bytes
コンパイル時間 5,711 ms
コンパイル使用メモリ 269,684 KB
実行使用メモリ 6,532 KB
最終ジャッジ日時 2023-10-20 12:28:04
合計ジャッジ時間 8,204 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 82 ms
4,800 KB
testcase_08 AC 109 ms
4,788 KB
testcase_09 AC 138 ms
4,800 KB
testcase_10 AC 143 ms
4,816 KB
testcase_11 AC 144 ms
4,840 KB
testcase_12 AC 115 ms
4,848 KB
testcase_13 AC 73 ms
4,840 KB
testcase_14 AC 101 ms
6,532 KB
testcase_15 AC 101 ms
6,532 KB
testcase_16 AC 46 ms
4,788 KB
testcase_17 AC 110 ms
6,532 KB
testcase_18 AC 47 ms
4,788 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 90 ms
5,444 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 56 ms
4,816 KB
testcase_25 AC 100 ms
4,816 KB
権限があれば一括ダウンロードができます

ソースコード

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