結果
問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
ユーザー |
![]() |
提出日時 | 2023-06-29 15:18:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 159 ms / 3,000 ms |
コード長 | 1,251 bytes |
コンパイル時間 | 2,289 ms |
コンパイル使用メモリ | 206,676 KB |
最終ジャッジ日時 | 2025-02-15 03:05:42 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template<typename T> using pq = priority_queue<T, vector<T>, greater<T>>; int main(){ int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; ll H, W, Y, X, cnt=1, now, h, w, nh, nw, e; cin >> H >> W >> Y >> X; vector<vector<ll>> A(H+1, vector<ll>(W+1)); pq<tuple<ll, ll, ll>> que; for (int i=1; i<=H; i++){ for (int j=1; j<=W; j++) cin >> A[i][j]; } now = A[Y][X]; A[Y][X] = 0; h = Y; w = X; for (int i=0; i<4; i++){ nh = h+dx[i]; nw = w+dy[i]; if (nh == 0 || nw == 0 || nh == H+1 || nw == W+1) continue; que.push({A[nh][nw], nh, nw}); A[nh][nw] = 0; } while(!que.empty()){ tie(e, h, w) = que.top(); que.pop(); if (e >= now){ cout << "No" << endl; return 0; } now += e; cnt++; for (int i=0; i<4; i++){ nh = h+dx[i]; nw = w+dy[i]; if (nh == 0 || nw == 0 || nh == H+1 || nw == W+1) continue; if (A[nh][nw] == 0) continue; que.push({A[nh][nw], nh, nw}); A[nh][nw] = 0; } } cout << (cnt == H*W ? "Yes" : "No") << endl; return 0; }