結果

問題 No.2731 Two Colors
ユーザー イチゴイチゴ
提出日時 2024-04-20 01:48:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 464 ms / 3,000 ms
コード長 1,724 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 182,756 KB
実行使用メモリ 21,504 KB
最終ジャッジ日時 2024-04-20 01:49:03
合計ジャッジ時間 8,914 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 439 ms
19,328 KB
testcase_01 AC 446 ms
19,456 KB
testcase_02 AC 464 ms
19,456 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 22 ms
5,376 KB
testcase_05 AC 15 ms
5,376 KB
testcase_06 AC 63 ms
6,912 KB
testcase_07 AC 71 ms
7,296 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 266 ms
16,512 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 275 ms
17,920 KB
testcase_12 AC 283 ms
16,512 KB
testcase_13 AC 228 ms
16,000 KB
testcase_14 AC 116 ms
9,472 KB
testcase_15 AC 9 ms
5,376 KB
testcase_16 AC 107 ms
9,472 KB
testcase_17 AC 154 ms
11,648 KB
testcase_18 AC 26 ms
5,376 KB
testcase_19 AC 110 ms
9,728 KB
testcase_20 AC 169 ms
12,032 KB
testcase_21 AC 34 ms
5,376 KB
testcase_22 AC 283 ms
17,536 KB
testcase_23 AC 68 ms
7,168 KB
testcase_24 AC 34 ms
5,504 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 223 ms
14,464 KB
testcase_27 AC 273 ms
17,408 KB
testcase_28 AC 175 ms
12,928 KB
testcase_29 AC 57 ms
6,656 KB
testcase_30 AC 97 ms
8,576 KB
testcase_31 AC 63 ms
7,040 KB
testcase_32 AC 350 ms
21,504 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:46:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   46 |         auto[m,mx,my] = *st[i].begin();
      |             ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
using vp = vector<pair<ll, ll>>;
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define resort(v) sort(v.rbegin(),v.rend())
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define per(i, n) for (ll i = n - 1; i >= 0; --i)
#define rep2(i, a, n) for (ll i = a; i < n; ++i)
#define per2(i, a, n) for (ll i = n - 1; i >= a; --i)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
const ll inf = 1ll << 60;
ll dx[] = {1, 0, -1, 0, -1, 1, -1, 1};
ll dy[] = {0, 1, 0, -1, -1, 1, 1, -1};

int main() {
    ll h,w;
    cin >> h >> w;
    vvll a(h,vll(w));
    rep(i,h){
        rep(j,w) cin >> a[i][j];
    }
    vvll dist(h,vll(w,-1));
    vector<set<tuple<ll,ll,ll>>> st(2);
    dist[0][0] = 0;
    dist[h-1][w-1] = 1;
    queue<P> q;
    q.push({0,0});
    q.push({h-1,w-1});
    ll i=0,ans=0;
    while (!q.empty()){
        ll x = q.front().first,y = q.front().second;
        q.pop();
        rep(k,4){
            if(x+dx[k]>=0&&y+dy[k]>=0&&x+dx[k]<h&&y+dy[k]<w&&dist[x+dx[k]][y+dy[k]]==-1){
                st[i].insert({a[x+dx[k]][y+dy[k]],x+dx[k],y+dy[k]});
            }
        }
        auto[m,mx,my] = *st[i].begin();
        q.push({mx,my});
        st[i].erase(*st[i].begin());
        dist[mx][my]=i;
        ans++;
        i = 1-i;
        rep(k,4){
            if(mx+dx[k]>=0&&my+dy[k]>=0&&mx+dx[k]<h&&my+dy[k]<w){
                if(dist[mx+dx[k]][my+dy[k]]==i){
                    cout << ans << endl;
                    return 0;
                } 
            }
        }
    }
}
0