結果
問題 | No.2731 Two Colors |
ユーザー | Aging1986 |
提出日時 | 2024-04-19 22:02:18 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 309 ms / 3,000 ms |
コード長 | 3,608 bytes |
コンパイル時間 | 2,876 ms |
コンパイル使用メモリ | 231,584 KB |
実行使用メモリ | 11,760 KB |
最終ジャッジ日時 | 2024-10-11 15:11:24 |
合計ジャッジ時間 | 7,511 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 309 ms
11,520 KB |
testcase_01 | AC | 307 ms
11,392 KB |
testcase_02 | AC | 308 ms
11,520 KB |
testcase_03 | AC | 3 ms
5,248 KB |
testcase_04 | AC | 11 ms
5,248 KB |
testcase_05 | AC | 9 ms
5,248 KB |
testcase_06 | AC | 30 ms
5,248 KB |
testcase_07 | AC | 30 ms
5,464 KB |
testcase_08 | AC | 6 ms
5,248 KB |
testcase_09 | AC | 105 ms
9,848 KB |
testcase_10 | AC | 4 ms
5,248 KB |
testcase_11 | AC | 128 ms
11,536 KB |
testcase_12 | AC | 104 ms
9,704 KB |
testcase_13 | AC | 106 ms
9,396 KB |
testcase_14 | AC | 50 ms
6,384 KB |
testcase_15 | AC | 7 ms
5,248 KB |
testcase_16 | AC | 52 ms
6,336 KB |
testcase_17 | AC | 67 ms
7,400 KB |
testcase_18 | AC | 14 ms
5,248 KB |
testcase_19 | AC | 53 ms
6,512 KB |
testcase_20 | AC | 66 ms
7,744 KB |
testcase_21 | AC | 15 ms
5,248 KB |
testcase_22 | AC | 117 ms
10,276 KB |
testcase_23 | AC | 31 ms
5,248 KB |
testcase_24 | AC | 17 ms
5,248 KB |
testcase_25 | AC | 3 ms
5,248 KB |
testcase_26 | AC | 89 ms
8,828 KB |
testcase_27 | AC | 113 ms
10,364 KB |
testcase_28 | AC | 80 ms
8,244 KB |
testcase_29 | AC | 26 ms
5,248 KB |
testcase_30 | AC | 44 ms
6,280 KB |
testcase_31 | AC | 32 ms
5,308 KB |
testcase_32 | AC | 148 ms
11,760 KB |
testcase_33 | AC | 2 ms
5,248 KB |
testcase_34 | AC | 2 ms
5,248 KB |
testcase_35 | AC | 2 ms
5,248 KB |
ソースコード
#pragma clang diagnostic push #pragma ide diagnostic ignored "cppcoreguidelines-narrowing-conversions" #pragma ide diagnostic ignored "hicpp-signed-bitwise" #pragma GCC optimize ("Ofast,unroll-loops") #pragma GCC optimize("no-stack-protector,fast-math") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<double> vd; typedef vector<string> vs; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<vll> vvll; typedef vector<vvll> vvvll; typedef vector<pii> vpii; typedef vector<vpii> vvpii; typedef vector<pll> vpll; typedef vector<vpll> vvpll; typedef vector<pdd> vpdd; typedef vector<vd> vvd; #define yn(ans) printf("%s\n", (ans)?"Yes":"No"); #define YN(ans) printf("%s\n", (ans)?"YES":"NO"); template<class T> bool chmax(T &a, T b) { if (a >= b) return false; a = b; return true; } template<class T> bool chmin(T &a, T b) { if (a <= b) return false; a = b; return true; } #define FOR(i, s, e, t) for ((i) = (s); (i) < (e); (i) += (t)) #define REP(i, e) for (int i = 0; i < (e); ++i) #define REP1(i, s, e) for (int i = (s); i < (e); ++i) #define RREP(i, e) for (int i = (e); i >= 0; --i) #define RREP1(i, e, s) for (int i = (e); i >= (s); --i) #define all(v) v.begin(), v.end() #define pb push_back #define qb pop_back #define pf push_front #define qf pop_front #define maxe max_element #define mine min_element ll inf = 1e18; #define DEBUG printf("%d\n", __LINE__); fflush(stdout); template<class T> void print(vector<T> &v, bool withSize = false) { if (withSize) cout << v.size() << endl; REP(i, v.size()) cout << v[i] << " "; cout << endl; } mt19937_64 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count()); int __FAST_IO__ = []() { std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); return 0; }(); #define TESTS int t; cin >> t; while (t--) #define TEST int main() { TEST { int H, W; cin >> H >> W; vvi v(H, vi(W)), c(H, vi(W, -1)); REP(i, H) REP(j, W) cin >> v[i][j]; vvi moves = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; typedef array<int, 3> node; priority_queue<node, vector<node>, greater<node>> pq, pq2; auto upd = [&](priority_queue<node, vector<node>, greater<node>> &q, int color, int x, int y) { // printf("paint %d %d %d\n", x, y, color); c[x][y] = color; for (auto &m: moves) { int nx = x + m[0], ny = y + m[1]; if (nx >= 0 && nx < H && ny >= 0 && ny < W) { if (c[nx][ny] == -1) q.push({v[nx][ny], nx, ny}); else if (c[nx][ny] != color) throw 1; } } }; upd(pq, 1, 0, 0); upd(pq2, 0, H - 1, W - 1); int ans = 0; while (1) { try { while (1) { if (pq.empty()) goto finish; auto p = pq.top(); pq.pop(); int x = p[1], y = p[2]; //printf("q1 %d %d %d\n", x, y, c[x][y]); if (c[x][y] == -1) { ans++; upd(pq, 1, x, y); break; } } } catch (int e) { break; } try { while (1) { if (pq2.empty()) goto finish; auto p = pq2.top(); pq2.pop(); int x = p[1], y = p[2]; //printf("q2 %d %d %d\n", x, y, c[x][y]); if (c[x][y] == -1) { ans++; upd(pq2, 0, x, y); break; } } } catch (int e) { break; } } finish: printf("%d\n", ans); } return 0; }