結果
| 問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
| コンテスト | |
| ユーザー |
keisuke6
|
| 提出日時 | 2022-05-21 09:55:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,666 bytes |
| コンパイル時間 | 1,830 ms |
| コンパイル使用メモリ | 187,152 KB |
| 実行使用メモリ | 8,512 KB |
| 最終ジャッジ日時 | 2024-09-20 11:20:18 |
| 合計ジャッジ時間 | 4,066 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 WA * 5 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define make_pair make_tuple
signed main(){
int H,W,X,Y;
cin>>H>>W>>X>>Y;
X--;
Y--;
vector<vector<int>> G(H,vector<int>(W));
for(int i=0;i<H;i++)for(int j=0;j<W;j++) cin>>G[i][j];
vector<vector<bool>> U(H,vector<bool>(W));
priority_queue<tuple<int,int,int>> s;
U[X][Y] = true;
int now = G[X][Y];
int i=X;
int j=Y;
if(i != 0 && G[i-1][j] < now && !U[i-1][j]){
s.push(make_pair(G[i-1][j],i-1,j));
U[i-1][j] = true;
}
if(j != 0 && G[i][j-1] < now && !U[i][j-1]){
U[i][j-1] = true;
s.push(make_pair(G[i][j-1],i,j-1));
}
if(i != H-1 && G[i+1][j] < now && !U[i+1][j]){
s.push(make_pair(G[i+1][j],i+1,j));
U[i+1][j] = true;
}
if(j != W-1 && G[i][j+1] < now && !U[i][j+1]){
U[i][j+1] = true;
s.push(make_pair(G[i][j+1],i,j+1));
}
int count = 1;
while(!s.empty()){
int a,b,c;
tie(a,b,c) = s.top();
/*cout<<b<<' '<<c<<endl;*/
s.pop();
if(a >= now){
cout<<"No"<<endl;
return 0;
}
now += a;
U[b][c] = true;
i=b;j=c;
if(i != 0 && G[i-1][j] < now && !U[i-1][j]){
U[i-1][j] = true;
s.push(make_pair(G[i-1][j],i-1,j));
}
if(j != 0 && G[i][j-1] < now && !U[i][j-1]){
U[i][j-1] = true;
s.push(make_pair(G[i][j-1],i,j-1));
}
if(i != H-1 && G[i+1][j] < now && !U[i+1][j]){
U[i+1][j] = true;
s.push(make_pair(G[i+1][j],i+1,j));
}
if(j != W-1 && G[i][j+1] < now && !U[i][j+1]){
U[i][j+1] = true;
s.push(make_pair(G[i][j+1],i,j+1));
}
count++;
}
if(count == H*W) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
keisuke6