結果
問題 | No.1949 足し算するだけのパズルゲーム(2) |
ユーザー |
![]() |
提出日時 | 2022-05-20 22:33:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 134 ms / 3,000 ms |
コード長 | 1,294 bytes |
コンパイル時間 | 4,026 ms |
コンパイル使用メモリ | 236,940 KB |
実行使用メモリ | 8,556 KB |
最終ジャッジ日時 | 2024-09-20 08:50:49 |
合計ジャッジ時間 | 6,447 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:44:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 44 | auto [a,v]=pq.top(); | ^
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using ll=long long; using Graph=vector<vector<int>>; #define MAX 3000 //#define MOD 1000000007 #define MOD 998244353 #define INF 1000000000 //#define INF 1000000000000000000 int di[4]={1,0,-1,0}; int dj[4]={0,1,0,-1}; int main(){ int H,W,Y,X; cin>>H>>W>>Y>>X; Y--;X--; vector<vector<ll>> A(H,vector<ll>(W)); for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ cin>>A[i][j]; } } priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq; vector<vector<int>> seen(H,vector<int>(W,0)); seen[Y][X]=1; ll sum=A[Y][X]; for(int k=0;k<4;k++){ int ni=Y+di[k]; int nj=X+dj[k]; if(ni<0||nj<0||ni>=H||nj>=W){ continue; } pq.push(make_pair(A[ni][nj],ni*W+nj)); seen[ni][nj]=1; } while(!pq.empty()){ auto [a,v]=pq.top(); int i=v/W; int j=v%W; pq.pop(); if(sum<=a){ cout<<"No"<<'\n'; return 0; } sum+=a; for(int k=0;k<4;k++){ int ni=i+di[k]; int nj=j+dj[k]; if(ni<0||nj<0||ni>=H||nj>=W){ continue; } if(seen[ni][nj]==1){ continue; } seen[ni][nj]=1; pq.push(make_pair(A[ni][nj],ni*W+nj)); } } cout<<"Yes"<<'\n'; }