結果
問題 |
No.2731 Two Colors
|
ユーザー |
![]() |
提出日時 | 2024-04-19 22:00:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,676 bytes |
コンパイル時間 | 2,511 ms |
コンパイル使用メモリ | 212,220 KB |
最終ジャッジ日時 | 2025-02-21 04:17:01 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 9 WA * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; vector<int> di = {-1, 0, 1, 0}; vector<int> dj = {0, 1, 0, -1}; int main() { int h, w; cin >> h >> w; vector<vector<int>> a(h, vector<int>(w)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> a[i][j]; } } auto inc = [&](int i, int j) { return (0 <= i && i < h && 0 <= j && j < w); }; vector<vector<int>> b(h, vector<int>(w, -1)); vector<vector<bool>> visit(h, vector<bool>(w, false)); b[0][0] = 1; visit[0][0] = true; b[h - 1][w - 1] = 0; visit[h - 1][w - 1] = true; vector<priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>>> pq(2); pq[1].push({a[0][1], 0, 1}); visit[0][1] = true; pq[1].push({a[1][0], 1, 0}); visit[1][0] = true; pq[0].push({a[h - 1][w - 2], h - 1, w - 2}); visit[h - 1][w - 2] = true; pq[0].push({a[h - 2][w - 1], h - 2, w - 1}); visit[h - 2][w - 1] = true; int cnt = 0; while (true) { cnt++; int id = cnt % 2; auto [x, i, j] = pq[id].top(); pq[id].pop(); b[i][j] = id; bool ok = true; for (int k = 0; k < 4; k++) { int ni = i + di[k], nj = j + dj[k]; if (!inc(ni, nj)) { continue; } if (b[ni][nj] == 1 - id) { ok = false; } else if (b[ni][nj] == -1 && !visit[ni][nj]) { visit[ni][nj] = true; pq[id].push({a[ni][nj], ni, nj}); } } if (!ok) { break; } } cout << cnt << endl; }