結果
問題 | No.1949 足し算するだけのパズルゲーム(2) |
ユーザー |
|
提出日時 | 2022-05-21 16:00:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 72 ms / 3,000 ms |
コード長 | 932 bytes |
コンパイル時間 | 1,784 ms |
コンパイル使用メモリ | 181,136 KB |
実行使用メモリ | 6,028 KB |
最終ジャッジ日時 | 2024-09-20 11:52:48 |
合計ジャッジ時間 | 3,663 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int H,W,sH,sW; cin>>H>>W>>sH>>sW; vector<vector<int>>A(H,vector<int>(W)); for(int i=0;i<H;i++){ for(int &j:A[i])cin>>j; } --sH,--sW; long long P=A[sH][sW]; int dh[4]={0,1,0,-1}; int dw[4]={-1,0,1,0}; vector<vector<bool>>vst(H,vector<bool>(W)); vst[sH][sW]=true; priority_queue<pair<int,array<int,2>>,vector<pair<int,array<int,2>>>,greater<pair<int,array<int,2>>>>pq; pq.push({0,{sH,sW}}); while(pq.size()){ int h=pq.top().second[0],w=pq.top().second[1],k=pq.top().first; pq.pop(); if(k>=P){ cout<<"No\n"; return 0; } P+=k; for(int i=0;i<4;i++){ if(h+dh[i]>=0&&h+dh[i]<H&&w+dw[i]>=0&&w+dw[i]<W&&!vst[h+dh[i]][w+dw[i]]){ vst[h+dh[i]][w+dw[i]]=true; pq.push({A[h+dh[i]][w+dw[i]],{h+dh[i],w+dw[i]}}); } } } cout<<"Yes\n"; }