結果
問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
ユーザー |
|
提出日時 | 2022-05-20 23:31:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 75 ms / 3,000 ms |
コード長 | 1,186 bytes |
コンパイル時間 | 2,241 ms |
コンパイル使用メモリ | 211,168 KB |
最終ジャッジ日時 | 2025-01-29 11:51:48 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int H,W,Y,X; cin >> H >> W >> Y >> X; Y--; X--; vector<vector<ll>> A(H, vector<ll>(W)); ll sum = 0; rep(i,H)rep(j,W) { cin >> A[i][j]; sum += A[i][j]; } using T = tuple<ll,int,int>; priority_queue<T,vector<T>,greater<T>> q; ll cur = 0; vector<vector<bool>> used(H, vector<bool>(W, false)); q.push({A[Y][X], Y, X}); int di[] = {0, 1, 0, -1}; int dj[] = {1, 0, -1, 0}; used[Y][X] = true; while(!q.empty()) { auto [a, i, j] = q.top(); q.pop(); if(!(i == Y && j == X) && cur <= a) { cout << "No" << endl; return 0; } cur += a; rep(d,4) { int ni = i + di[d], nj = j + dj[d]; if(0 <= ni && ni < H && 0 <= nj && nj < W) { if(used[ni][nj] == false) { q.push({A[ni][nj], ni, nj}); used[ni][nj] = true; } } } } cout << (sum == cur ? "Yes" : "No") << endl; }