結果
問題 | No.1323 うしらずSwap |
ユーザー | Luzhiled |
提出日時 | 2020-12-07 23:18:34 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,238 bytes |
コンパイル時間 | 2,298 ms |
コンパイル使用メモリ | 179,816 KB |
実行使用メモリ | 123,516 KB |
最終ジャッジ日時 | 2023-10-21 09:33:05 |
合計ジャッジ時間 | 21,880 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge10 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 2 ms
4,348 KB |
testcase_04 | AC | 2 ms
4,348 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 2 ms
4,348 KB |
testcase_07 | AC | 1 ms
4,348 KB |
testcase_08 | AC | 1 ms
4,348 KB |
testcase_09 | AC | 1 ms
4,348 KB |
testcase_10 | AC | 2 ms
4,348 KB |
testcase_11 | AC | 2 ms
4,348 KB |
testcase_12 | WA | - |
testcase_13 | AC | 2 ms
4,348 KB |
testcase_14 | AC | 2 ms
4,348 KB |
testcase_15 | AC | 1 ms
4,348 KB |
testcase_16 | AC | 184 ms
95,796 KB |
testcase_17 | AC | 510 ms
95,796 KB |
testcase_18 | AC | 181 ms
96,060 KB |
testcase_19 | AC | 522 ms
95,796 KB |
testcase_20 | AC | 187 ms
95,796 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 187 ms
96,060 KB |
testcase_27 | AC | 186 ms
96,060 KB |
testcase_28 | AC | 378 ms
95,796 KB |
testcase_29 | AC | 190 ms
96,060 KB |
testcase_30 | AC | 367 ms
95,796 KB |
testcase_31 | AC | 185 ms
95,796 KB |
testcase_32 | AC | 448 ms
95,796 KB |
testcase_33 | AC | 650 ms
108,732 KB |
testcase_34 | AC | 706 ms
113,748 KB |
testcase_35 | AC | 757 ms
116,388 KB |
testcase_36 | AC | 716 ms
117,972 KB |
testcase_37 | AC | 742 ms
118,500 KB |
testcase_38 | AC | 916 ms
121,932 KB |
testcase_39 | AC | 858 ms
122,724 KB |
testcase_40 | AC | 946 ms
122,988 KB |
testcase_41 | AC | 920 ms
123,516 KB |
testcase_42 | AC | 846 ms
123,252 KB |
testcase_43 | AC | 145 ms
79,428 KB |
testcase_44 | AC | 306 ms
81,804 KB |
testcase_45 | AC | 262 ms
86,820 KB |
testcase_46 | AC | 314 ms
81,804 KB |
testcase_47 | AC | 169 ms
82,068 KB |
testcase_48 | AC | 146 ms
79,428 KB |
testcase_49 | AC | 303 ms
81,804 KB |
testcase_50 | AC | 134 ms
77,316 KB |
testcase_51 | AC | 74 ms
68,604 KB |
testcase_52 | AC | 100 ms
73,092 KB |
testcase_53 | AC | 307 ms
82,068 KB |
testcase_54 | AC | 97 ms
73,356 KB |
testcase_55 | AC | 315 ms
82,068 KB |
testcase_56 | AC | 87 ms
70,980 KB |
testcase_57 | AC | 389 ms
86,820 KB |
testcase_58 | AC | 2 ms
4,348 KB |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | AC | 2 ms
4,348 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int h, w; cin >> h >> w; auto to_v = [w](int y, int x) { return y * w + x; }; int Ya, Xa, Yb, Xb; cin >> Ya >> Xa >> Yb >> Xb; int a = to_v(Ya - 1, Xa - 1); int b = to_v(Yb - 1, Xb - 1); vector< string > ss(h); for (auto &s : ss) cin >> s; int V = h * w; vector< vector< int > > G(V); constexpr int dy[] = {-1, 0, 1, 0}; constexpr int dx[] = {0, 1, 0, -1}; for (int y = 1; y < h - 1; y++) { for (int x = 1; x < w - 1; x++) { if (ss[y][x] == '#') continue; int v = to_v(y, x); for (int i = 0; i < 4; i++) { int ny = y + dy[i]; int nx = x + dx[i]; if (ss[ny][nx] == '#') continue; int u = to_v(ny, nx); G[v].emplace_back(u); } } } constexpr int inf = 1001001001; vector< int > rs(V); auto bfs = [&](int s) { queue< int > que; que.emplace(s); vector< int > res(V, inf); res[s] = 0; rs.assign(V, 0); rs[s] = 1; while (not que.empty()) { int v = que.front(); que.pop(); for (auto &u : G[v]) { if (res[u] == res[v] + 1) { rs[u] = 2; } if (res[u] > res[v] + 1) { res[u] = res[v] + 1; rs[u] = rs[v]; que.emplace(u); } } } return res; }; auto da = bfs(a); auto db = bfs(b); int ans = inf; if (rs[a] == 0) { ans = -1; } if (rs[a] >= 2) { ans = da[b] + db[a]; } for (int y = 1; y < h - 1; y++) { for (int x = 1; x < w - 1; x++) { int v = to_v(y, x); if (rs[v] == 0) continue; if ((int)G[v].size() < 3) continue; int af = v; for (int i = 0; i < 4; i++) { int u = to_v(y + dy[i], x + dx[i]); if (da[u] > da[af]) continue; af = u; } int bf = v; for (int i = 0; i < 4; i++) { int u = to_v(y + dy[i], x + dx[i]); if (db[u] > db[bf]) continue; bf = u; } if (af == bf or af == v or bf == v) { ans = min(ans, 2 * (da[v] + db[v]) + 4); } else { ans = min(ans, 2 * (da[v] + db[v]) + 2); } } } if (ans == inf) { ans = -1; } cout << ans << endl; }