結果
問題 | No.2731 Two Colors |
ユーザー | cled0328 |
提出日時 | 2024-04-19 21:56:23 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,139 ms / 3,000 ms |
コード長 | 2,046 bytes |
コンパイル時間 | 2,516 ms |
コンパイル使用メモリ | 216,640 KB |
実行使用メモリ | 96,032 KB |
最終ジャッジ日時 | 2024-04-19 21:56:53 |
合計ジャッジ時間 | 16,817 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,091 ms
96,032 KB |
testcase_01 | AC | 1,134 ms
96,012 KB |
testcase_02 | AC | 1,139 ms
96,020 KB |
testcase_03 | AC | 7 ms
5,376 KB |
testcase_04 | AC | 38 ms
6,376 KB |
testcase_05 | AC | 27 ms
5,376 KB |
testcase_06 | AC | 118 ms
11,012 KB |
testcase_07 | AC | 132 ms
12,508 KB |
testcase_08 | AC | 18 ms
5,376 KB |
testcase_09 | AC | 608 ms
36,824 KB |
testcase_10 | AC | 9 ms
5,376 KB |
testcase_11 | AC | 654 ms
38,856 KB |
testcase_12 | AC | 591 ms
36,684 KB |
testcase_13 | AC | 548 ms
31,812 KB |
testcase_14 | AC | 231 ms
18,696 KB |
testcase_15 | AC | 19 ms
5,376 KB |
testcase_16 | AC | 224 ms
16,860 KB |
testcase_17 | AC | 367 ms
22,012 KB |
testcase_18 | AC | 51 ms
6,880 KB |
testcase_19 | AC | 264 ms
17,416 KB |
testcase_20 | AC | 404 ms
27,180 KB |
testcase_21 | AC | 59 ms
7,192 KB |
testcase_22 | AC | 691 ms
38,412 KB |
testcase_23 | AC | 139 ms
11,496 KB |
testcase_24 | AC | 64 ms
7,788 KB |
testcase_25 | AC | 5 ms
5,376 KB |
testcase_26 | AC | 511 ms
31,836 KB |
testcase_27 | AC | 655 ms
39,240 KB |
testcase_28 | AC | 387 ms
25,128 KB |
testcase_29 | AC | 105 ms
10,220 KB |
testcase_30 | AC | 199 ms
17,208 KB |
testcase_31 | AC | 133 ms
11,952 KB |
testcase_32 | AC | 827 ms
43,464 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 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ int h,w;cin>>h>>w; vector<vector<long long>> a(h,vector<long long>(w)); unordered_map<long long,pair<int,int>> mp; for(int i=0;i<h;i++)for(int j=0;j<w;j++){ cin>>a[i][j]; mp[a[i][j]]={i,j}; } unordered_set<long long> st0,st1; priority_queue<long long,vector<long long>,greater<long long>> pq1,pq0; vector<int> dx={1,0,-1,0},dy={0,1,0,-1}; int idx=1; pq1.push(a[0][0]); pq0.push(a[h-1][w-1]); while(!pq1.empty()||!pq0.empty()){ if((idx&1)==0){ idx++; while(!pq0.empty()&&st0.count(pq0.top()))pq0.pop(); if(pq0.empty()){ continue; } auto x=pq0.top();pq0.pop(); st0.insert(x); for(int i=0;i<4;i++){ if(mp[x].first+dx[i]<0||mp[x].first+dx[i]>=h)continue; if(mp[x].second+dy[i]<0||mp[x].second+dy[i]>=w)continue; if(st0.count(a[mp[x].first+dx[i]][mp[x].second+dy[i]]))continue; if(st1.count(a[mp[x].first+dx[i]][mp[x].second+dy[i]])){ cout<<idx-3<<"\n"; return 0; } pq0.push(a[mp[x].first+dx[i]][mp[x].second+dy[i]]); } }else{ idx++; while(!pq1.empty()&&st1.count(pq1.top()))pq1.pop(); if(pq1.empty()){ continue; } auto x=pq1.top();pq1.pop(); st1.insert(x); for(int i=0;i<4;i++){ if(mp[x].first+dx[i]<0||mp[x].first+dx[i]>=h)continue; if(mp[x].second+dy[i]<0||mp[x].second+dy[i]>=w)continue; if(st1.count(a[mp[x].first+dx[i]][mp[x].second+dy[i]]))continue; if(st0.count(a[mp[x].first+dx[i]][mp[x].second+dy[i]])){ cout<<idx-3<<"\n"; return 0; } pq1.push(a[mp[x].first+dx[i]][mp[x].second+dy[i]]); } } } }