結果
問題 | No.323 yuki国 |
ユーザー |
![]() |
提出日時 | 2018-11-01 17:03:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 133 ms / 5,000 ms |
コード長 | 1,447 bytes |
コンパイル時間 | 2,444 ms |
コンパイル使用メモリ | 207,068 KB |
最終ジャッジ日時 | 2025-01-06 15:18:28 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h>using namespace std;using i64 = int64_t;using vi = vector<i64>;using vvi = vector<vi>;vvi board;int main() {int h, w;cin >> h >> w;int a, si, sj, b, gi, gj;cin >> a >> si >> sj >> b >> gi >> gj;board = vvi(h, vi(w));for (int i = 0; i < h; i++) {string s;cin >> s;for (int j = 0; j < w; j++) {board[i][j] = s[j] == '*';}}vector<vvi> dp(1200, vvi(h, vi(w, 1e9)));using ii = pair<int, int>;using iii = pair<ii, int>;queue<iii> que;dp[a][si][sj] = 0;que.push(iii(ii(si, sj), a));int dx[] = {-1, 1, 0, 0};int dy[] = {0, 0, -1, 1};auto ok = [&](int x, int y) {return 0 <= x && x < h && 0 <= y && y < w;};while (que.size()) {iii t = que.front();que.pop();for (int i = 0; i < 4; i++) {int x = t.first.first + dx[i];int y = t.first.second + dy[i];if (ok(x, y)) {int sz = t.second + (board[x][y] ? 1 : -1);if (sz <= 0 || sz >= 1200) continue;if (dp[t.second][t.first.first][t.first.second] + 1 < dp[sz][x][y]) {dp[sz][x][y] = dp[t.second][t.first.first][t.first.second] + 1;que.push(iii(ii(x, y), sz));}}}}cout << (dp[b][gi][gj] == 1e9 ? "No" : "Yes") << endl;}