結果
問題 | No.1949 足し算するだけのパズルゲーム(2) |
ユーザー |
|
提出日時 | 2022-05-21 17:51:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 76 ms / 3,000 ms |
コード長 | 1,873 bytes |
コンパイル時間 | 1,977 ms |
コンパイル使用メモリ | 148,700 KB |
最終ジャッジ日時 | 2025-01-29 13:06:46 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#pragma GCC optimize("Ofast") #include <iostream> #include <vector> #include <algorithm> #include <map> #include <queue> #include <cstdio> #include <ctime> #include <assert.h> #include <chrono> #include <random> #include <numeric> #include <set> #include <deque> #include <stack> #include <sstream> #include <utility> #include <cstring> #include <unordered_map> #include <unordered_set> #include <tuple> #include <array> #include <bitset> using namespace std; typedef long long int ll; typedef unsigned long long ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } inline double time() { return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9; } int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1}; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int h,w; cin >> h >> w; int x,y; cin >> x >> y; x--; y--; vector<vector<int>> a(h,vector<int>(w)); for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ cin >> a[i][j]; } } vector<vector<bool>> done(h,vector<bool>(w,false)); done[x][y] = 1; using P = pair<ll,pair<int,int>>; priority_queue<P,vector<P>,greater<P>> pq; pq.push({-1,{x,y}}); ll cur = 0; while(pq.size()){ auto p = pq.top(); pq.pop(); if(p.first >= cur){ cout << "No" << endl; return 0; } int x = p.second.first, y = p.second.second; cur += a[x][y]; for(int i=0;i<4;i++){ int nx = x+dx[i]; int ny = y+dy[i]; if(0 <= nx and nx < h and 0 <= ny and ny < w and !done[nx][ny]){ done[nx][ny] = 1; pq.push({a[nx][ny],{nx,ny}}); } } } cout << "Yes" << endl; }