結果
問題 | No.2731 Two Colors |
ユーザー | AwashAmityOak |
提出日時 | 2024-04-19 22:02:34 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 459 ms / 3,000 ms |
コード長 | 3,043 bytes |
コンパイル時間 | 5,534 ms |
コンパイル使用メモリ | 320,492 KB |
実行使用メモリ | 19,984 KB |
最終ジャッジ日時 | 2024-10-11 15:12:11 |
合計ジャッジ時間 | 12,763 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 455 ms
19,072 KB |
testcase_01 | AC | 458 ms
19,072 KB |
testcase_02 | AC | 459 ms
18,944 KB |
testcase_03 | AC | 5 ms
6,820 KB |
testcase_04 | AC | 23 ms
6,816 KB |
testcase_05 | AC | 15 ms
6,820 KB |
testcase_06 | AC | 59 ms
6,820 KB |
testcase_07 | AC | 73 ms
7,064 KB |
testcase_08 | AC | 11 ms
6,816 KB |
testcase_09 | AC | 271 ms
15,692 KB |
testcase_10 | AC | 5 ms
6,820 KB |
testcase_11 | AC | 244 ms
19,924 KB |
testcase_12 | AC | 269 ms
15,660 KB |
testcase_13 | AC | 209 ms
15,020 KB |
testcase_14 | AC | 118 ms
9,200 KB |
testcase_15 | AC | 10 ms
6,816 KB |
testcase_16 | AC | 100 ms
8,988 KB |
testcase_17 | AC | 147 ms
10,908 KB |
testcase_18 | AC | 26 ms
6,820 KB |
testcase_19 | AC | 102 ms
9,128 KB |
testcase_20 | AC | 177 ms
11,244 KB |
testcase_21 | AC | 27 ms
6,820 KB |
testcase_22 | AC | 272 ms
17,852 KB |
testcase_23 | AC | 64 ms
6,844 KB |
testcase_24 | AC | 31 ms
6,820 KB |
testcase_25 | AC | 3 ms
6,820 KB |
testcase_26 | AC | 219 ms
13,756 KB |
testcase_27 | AC | 271 ms
18,440 KB |
testcase_28 | AC | 167 ms
13,948 KB |
testcase_29 | AC | 52 ms
6,820 KB |
testcase_30 | AC | 98 ms
9,036 KB |
testcase_31 | AC | 59 ms
7,528 KB |
testcase_32 | AC | 322 ms
19,984 KB |
testcase_33 | AC | 2 ms
6,816 KB |
testcase_34 | AC | 2 ms
6,820 KB |
testcase_35 | AC | 2 ms
6,816 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; typedef long long ll; typedef long double ld; #define int ll #define OVERLOAD_REP(_1, _2, _3, name, ...) name #define REP2(i, l, r) for (int i = (int)(l); i < (int)(r); i++) #define REP1(i, n) REP2(i, 0, n) #define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__) #define RREP2(i, l, r) for (int i = (int)(l)-1; i >= (int)(r); i--) #define RREP1(i, n) RREP2(i, n, 0) #define rrep(...) OVERLOAD_REP(__VA_ARGS__, RREP2, RREP1)(__VA_ARGS__) #define all(...) begin(__VA_ARGS__), end(__VA_ARGS__) #define rall(...) rbegin(__VA_ARGS__), rend(__VA_ARGS__) #define debug(x) cerr << #x << ": " << (x) << endl #define pb push_back #define mp make_pair #define mt make_tuple const int INF = 4e18; const int MOD = 1e9 + 7; const int MOD2 = 998244353; template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template<class... T> void input(T&... args) { ((cin >> args), ...); } template<class... T> void print(T... args) { ((cout << args << " "), ...); } template<class... T> void println(T... args) { print(args...); cout << endl; } signed main() { int H, W; input(H, W); vector<vector<int>> A(H, vector<int>(W)); rep(i, H) rep(j, W) input(A[i][j]); vector<vector<int>> B(H, vector<int>(W, -1)); B[0][0] = 1; B[H-1][W-1] = 0; priority_queue< pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>> > color0_next; color0_next.push(mp(A[H-2][W-1], mp(H-2, W-1))); color0_next.push(mp(A[H-1][W-2], mp(H-1, W-2))); priority_queue< pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>> > color1_next; color1_next.push(mp(A[1][0], mp(1, 0))); color1_next.push(mp(A[0][1], mp(0, 1))); int i = 1; while (true) { if (i % 2 == 0) { while (!color0_next.empty()) { auto [di, dj] = color0_next.top().second; color0_next.pop(); if (B[di][dj] == -1) { B[di][dj] = 0; for (auto [ddi, ddj] : {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)}) { ddi = max(0LL, min(H-1, di + ddi)); ddj = max(0LL, min(W-1, dj + ddj)); if (B[ddi][ddj] == 1) { println(i); return 0; } else if (B[ddi][ddj] == -1) { color0_next.push(mp(A[ddi][ddj], mp(ddi, ddj))); } } break; } } } else { while (!color1_next.empty()) { auto [di, dj] = color1_next.top().second; color1_next.pop(); if (B[di][dj] == -1) { B[di][dj] = 1; for (auto [ddi, ddj] : {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)}) { ddi = max(0LL, min(H-1, di + ddi)); ddj = max(0LL, min(W-1, dj + ddj)); if (B[ddi][ddj] == 0) { println(i); return 0; } else if (B[ddi][ddj] == -1) { color1_next.push(mp(A[ddi][ddj], mp(ddi, ddj))); } } break; } } } ++i; } }