結果
問題 | No.2731 Two Colors |
ユーザー | mayocorn |
提出日時 | 2024-04-19 21:49:31 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 300 ms / 3,000 ms |
コード長 | 3,535 bytes |
コンパイル時間 | 4,566 ms |
コンパイル使用メモリ | 276,484 KB |
実行使用メモリ | 21,120 KB |
最終ジャッジ日時 | 2024-10-11 14:46:25 |
合計ジャッジ時間 | 9,639 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 300 ms
19,200 KB |
testcase_01 | AC | 298 ms
19,200 KB |
testcase_02 | AC | 299 ms
19,328 KB |
testcase_03 | AC | 3 ms
5,248 KB |
testcase_04 | AC | 13 ms
5,248 KB |
testcase_05 | AC | 11 ms
5,248 KB |
testcase_06 | AC | 39 ms
6,784 KB |
testcase_07 | AC | 35 ms
6,912 KB |
testcase_08 | AC | 7 ms
5,248 KB |
testcase_09 | AC | 126 ms
16,128 KB |
testcase_10 | AC | 4 ms
5,248 KB |
testcase_11 | AC | 193 ms
17,664 KB |
testcase_12 | AC | 125 ms
16,256 KB |
testcase_13 | AC | 159 ms
15,616 KB |
testcase_14 | AC | 60 ms
9,344 KB |
testcase_15 | AC | 8 ms
5,248 KB |
testcase_16 | AC | 72 ms
9,088 KB |
testcase_17 | AC | 92 ms
11,264 KB |
testcase_18 | AC | 18 ms
5,248 KB |
testcase_19 | AC | 76 ms
9,600 KB |
testcase_20 | AC | 75 ms
11,520 KB |
testcase_21 | AC | 19 ms
5,248 KB |
testcase_22 | AC | 158 ms
17,536 KB |
testcase_23 | AC | 42 ms
7,040 KB |
testcase_24 | AC | 21 ms
5,248 KB |
testcase_25 | AC | 3 ms
5,248 KB |
testcase_26 | AC | 111 ms
14,336 KB |
testcase_27 | AC | 144 ms
17,152 KB |
testcase_28 | AC | 112 ms
12,672 KB |
testcase_29 | AC | 37 ms
6,400 KB |
testcase_30 | AC | 55 ms
8,576 KB |
testcase_31 | AC | 44 ms
6,912 KB |
testcase_32 | AC | 212 ms
21,120 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 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; // type typedef long long ll; typedef long double ld; using i128 = __int128_t; template<class T> using pq = priority_queue<T>; template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>; template<class T> using v = vector<T>; #define V vector #define pl pair<ll, ll> #define vl v<ll> #define vp v<pl> #define vm v<mint> // IN-OUT #define NYAN ios::sync_with_stdio(false);cin.tie(nullptr);cout<<fixed<<setprecision(15); ostream &operator<<(ostream &os, const i128 &v) { if(v == 0) { return (os << "0"); } i128 num = v; if(v < 0) { os << '-'; num = -num; } string s; for(; num > 0; num /= 10) { s.push_back((char)(num % 10) + '0'); } reverse(s.begin(), s.end()); return (os << s); } void Yes(bool b=1) { cout << ( b == 1 ? "Yes" : "No" ) << "\n"; } void YES(bool b=1) { cout << ( b == 1 ? "YES" : "NO" ) << "\n"; } void No(bool b=1) { cout << ( b == 1 ? "No" : "Yes" ) << "\n"; } void NO(bool b=1) { cout << ( b == 1 ? "NO" : "YES" ) << "\n"; } void CIN() {} template <typename T, class... U> void CIN(T &t, U &...u) { cin >> t; CIN(u...); } void COUT() { cout << "\n"; } template <typename T, class... U, char sep = ' '> void COUT(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << sep; COUT(u...); } #define dump(x) cerr << #x << ":"<< x << "\n"; #define vdump(x) rep(repeat, sz(x)) cerr << repeat << ":" << x[repeat] << "\n"; // macro #define bp __builtin_popcountll #define ALL(x) x.begin(),x.end() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define reps(i, s, n) for (ll i = s; i < (ll)(n); i++) #define sz(x) (ll)x.size() ll xd[]={0, 1, 0, -1, 1, 1, -1, -1}; ll yd[]={1, 0, -1, 0, 1, -1, -1, 1}; // function template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } template<typename T>int bl(T x) { int s = 0; while(x) {x >>= 1; s++;} return s; } // bitlength ll rmax(ll a, ll b){return max(a, b);} ll rmin(ll a, ll b){return min(a, b);} ll rsum(ll a, ll b){return a + b;} ll rzero(){return 0;} // constant long double PI = 3.14159265358979; #define INF32 2147483647 #define INF64 9223372036854775807 #define INF 922337203685477580 using mint = modint998244353; // using mint = modint1000000007; /* SOLVE BEGIN ************************************************************************** */ void solve() { ll h, w; cin >> h >> w; v<vl> g(h, vl(w)); rep(i, h)rep(j, w) cin >> g[i][j]; v<vl> used(h, vl(w, -1)); used[0][0] = 1; used[h - 1][w - 1] = 0; v<set<tuple<ll, ll, ll>>> s(2); auto ng = [&](ll x, ll y){ return x < 0 || y < 0 || x >= h || y >= w; }; rep(i, 4){ ll x = xd[i], y = yd[i]; if(ng(x, y)) continue; s[1].emplace(g[x][y], x, y); } rep(i, 4){ ll x = xd[i] + h - 1, y = yd[i] + w - 1; if(ng(x, y)) continue; s[0].emplace(g[x][y], x, y); } ll ans = 0; reps(i, 1, INF){ ll mod = i % 2; if(sz(s[mod]) == 0) break; ans++; auto it = s[mod].begin(); auto [num, x, y] = *it; s[mod].erase(*it); used[x][y] = mod; rep(k, 4){ ll nx = x + xd[k], ny = y + yd[k]; if(ng(nx, ny)) continue; if(used[nx][ny] == (mod ^ 1)){ cout << ans << "\n"; return; } if(used[nx][ny] == -1) s[mod].emplace(g[nx][ny], nx, ny); } } cout << ans << "\n"; } int main() { NYAN solve(); return 0; }