結果
問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
ユーザー |
|
提出日時 | 2022-05-21 00:09:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 174 ms / 3,000 ms |
コード長 | 1,669 bytes |
コンパイル時間 | 1,895 ms |
コンパイル使用メモリ | 181,900 KB |
実行使用メモリ | 11,072 KB |
最終ジャッジ日時 | 2024-09-20 10:34:12 |
合計ジャッジ時間 | 4,715 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; #define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i) #define rep(i, n) drep(i, 0, n - 1) #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll INF = 1LL << 60; const ll N_MAX = 2e5; int main(){ ll h, w, y, x; cin >> h >> w >> y >> x; y--; x--; vector<vector<ll>> a(h, vector<ll>(w)); rep(i, h) rep(j, w) cin >> a[i][j]; priority_queue<pll, vector<pll>, greater<pll>> PQ; PQ.push({a[y][x], y*w+x}); ll di[4] = {0, 1, 0, -1}; ll dj[4] = {1, 0, -1, 0}; ll sum = a[y][x]; rep(k, 4){ ll next_i = y + di[k]; ll next_j = x + dj[k]; if(next_i < 0 || next_j < 0 || h <= next_i || w <= next_j) continue; PQ.push({a[next_i][next_j], next_i*w+next_j}); } vector<vector<bool>> check(h, vector<bool>(w, false)); check[y][x] = true; while(!PQ.empty()){ ll now_i = PQ.top().se/w; ll now_j = PQ.top().se%w; PQ.pop(); if(check[now_i][now_j]) continue; if(sum <= a[now_i][now_j]){ cout << "No" << endl; return 0; } check[now_i][now_j] = true; sum += a[now_i][now_j]; rep(k, 4){ ll next_i = now_i + di[k]; ll next_j = now_j + dj[k]; if (next_i < 0 || next_j < 0 || h <= next_i || w <= next_j) continue; if(check[next_i][next_j]) continue; PQ.push({a[next_i][next_j], next_i*w + next_j}); } } cout << "Yes" << endl; }