結果
| 問題 |
No.1949 足し算するだけのパズルゲーム(2)
|
| コンテスト | |
| ユーザー |
Kome_soudou
|
| 提出日時 | 2022-05-21 00:00:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 130 ms / 3,000 ms |
| コード長 | 1,200 bytes |
| コンパイル時間 | 2,017 ms |
| コンパイル使用メモリ | 181,136 KB |
| 実行使用メモリ | 7,488 KB |
| 最終ジャッジ日時 | 2024-09-20 10:24:49 |
| 合計ジャッジ時間 | 4,013 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int64_t dy[4] = {1, 0, -1, 0};
const int64_t dx[4] = {0, 1, 0, -1};
int main()
{
int64_t H, W, Y, X;
cin >> H >> W >> Y >> X;
Y--; X--;
vector<vector<int64_t>> A(H, vector<int64_t>(W));
for(int64_t i = 0; i < H; i++) for(int64_t j = 0; j < W; j++) cin >> A[i][j];
vector<vector<bool>> C(H, vector<bool>(W));
int64_t P = A[Y][X];
C[Y][X] = true;
priority_queue<pair<int64_t, int64_t>, vector<pair<int64_t, int64_t>>, greater<pair<int64_t, int64_t>>> pq;
int64_t y, x;
for(int dir = 0; dir < 4; dir++)
{
y = Y + dy[dir];
x = X + dx[dir];
if(y < 0 || y >= H || x < 0 || x >= W) continue;
C[y][x] = true;
pq.push({A[y][x], y * W + x});
}
while(!pq.empty())
{
pair<int64_t, int64_t> p = pq.top();
y = p.second / W;
x = p.second % W;
pq.pop();
if(P <= p.first)
{
cout << "No" << endl;
return 0;
}
P += p.first;
for(int dir = 0; dir < 4; dir++)
{
int64_t ny = y + dy[dir];
int64_t nx = x + dx[dir];
if(ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
if(C[ny][nx]) continue;
C[ny][nx] = true;
pq.push({A[ny][nx], ny * W + nx});
}
}
cout << "Yes" << endl;
return 0;
}
Kome_soudou