結果
問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
ユーザー |
|
提出日時 | 2022-05-21 00:05:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 149 ms / 3,000 ms |
コード長 | 1,772 bytes |
コンパイル時間 | 4,147 ms |
コンパイル使用メモリ | 259,540 KB |
最終ジャッジ日時 | 2025-01-29 12:11:42 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; //#define DISABLE_PRINT #if defined(ENABLE_PRINT) && !defined(DISABLE_PRINT) #define P(...) fprintf(stderr, __VA_ARGS__) #define P2(fmt) fprintf(stderr, fmt) #define LP fprintf(stderr, "L: %d\n", __LINE__) #else #define P(...) ((void)0) #define P2(fmt) ((void)0) #define LP ((void)0) #endif #define rep(i, n) for(int i = 0; i < (int)(n); ++i) #define ALL(x) x.begin(),x.end() using ll = long long; using ull = unsigned long long; pair<int, int> diffs[] = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} }; int main(int, const char**) { int H, W, Y, X; cin >> H >> W >> Y >> X; Y--; X--; struct V { int y; int x; int v; }; vector<vector<bool>> done(H, vector<bool>(W)); vector<vector<int>> A(H, vector<int>(W)); rep(i, H) rep(j, W) cin >> A[i][j]; ll p = 0; p += A[Y][X]; auto comp = [](const V& a, const V& b) { return a.v > b.v; }; priority_queue<V, vector<V>, decltype(comp)> q{comp}; auto push = [&](int y, int x) { P("pos(%d, %d)\n", y, x); assert(done[y][x]); for(auto diff : diffs) { auto ny = y + diff.first; auto nx = x + diff.second; if(ny < 0 || nx < 0 || ny >= H || nx >= W) continue; if(done[ny][nx]) continue; q.push({ny, nx, A[ny][nx]}); done[ny][nx] = true; } }; done[Y][X] = true; push(Y, X); int count = 0; while(!q.empty()) { auto t = q.top(); q.pop(); if(p <= t.v) break; p += t.v; push(t.y, t.x); count++; } if(count == H * W - 1) { cout << "Yes" << endl; } else cout << "No" << endl; return 0; }