結果
問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
ユーザー |
![]() |
提出日時 | 2022-05-20 23:29:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 136 ms / 3,000 ms |
コード長 | 1,376 bytes |
コンパイル時間 | 1,693 ms |
コンパイル使用メモリ | 182,936 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-20 09:56:32 |
合計ジャッジ時間 | 4,104 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
/** * @FileName a.cpp * @Author kanpurin * @Created 2022.05.20 23:29:04 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; int main() { int h,w,x,y; cin >> h >> w >> x >> y; x--;y--; vector<vector<int>> a(h,vector<int>(w)); vector<vector<bool>> used(h,vector<bool>(w)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> a[i][j]; } } using P = pair<int,pair<int,int>>; priority_queue<P,vector<P>,greater<P>> pq; int dx[] = {0,1,0,-1}; int dy[] = {1,0,-1,0}; for (int i = 0; i < 4; i++) { int nx = x + dx[i]; int ny = y + dy[i]; if (nx < 0 || ny < 0 || nx >= h || ny >= w || used[nx][ny]) continue; pq.push({a[nx][ny],{nx,ny}}); used[nx][ny] = true; } used[x][y] = true; ll total = a[x][y]; while(!pq.empty()) { auto p = pq.top(); pq.pop(); if (total <= p.first) { puts("No"); return 0; } total += p.first; for (int i = 0; i < 4; i++) { int nx = p.second.first + dx[i]; int ny = p.second.second + dy[i]; if (nx < 0 || ny < 0 || nx >= h || ny >= w || used[nx][ny]) continue; pq.push({a[nx][ny],{nx,ny}}); used[nx][ny] = true; } } puts("Yes"); return 0; }