結果
問題 | No.2731 Two Colors |
ユーザー | twooimp2 |
提出日時 | 2024-04-19 22:59:25 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 947 ms / 3,000 ms |
コード長 | 1,691 bytes |
コンパイル時間 | 2,540 ms |
コンパイル使用メモリ | 212,644 KB |
実行使用メモリ | 81,920 KB |
最終ジャッジ日時 | 2024-04-19 22:59:57 |
合計ジャッジ時間 | 14,550 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 925 ms
81,792 KB |
testcase_01 | AC | 907 ms
81,792 KB |
testcase_02 | AC | 947 ms
81,920 KB |
testcase_03 | AC | 5 ms
6,944 KB |
testcase_04 | AC | 35 ms
7,296 KB |
testcase_05 | AC | 23 ms
6,940 KB |
testcase_06 | AC | 104 ms
13,696 KB |
testcase_07 | AC | 123 ms
16,896 KB |
testcase_08 | AC | 15 ms
6,940 KB |
testcase_09 | AC | 490 ms
54,272 KB |
testcase_10 | AC | 7 ms
6,944 KB |
testcase_11 | AC | 492 ms
44,288 KB |
testcase_12 | AC | 480 ms
54,016 KB |
testcase_13 | AC | 413 ms
38,272 KB |
testcase_14 | AC | 207 ms
25,088 KB |
testcase_15 | AC | 13 ms
6,944 KB |
testcase_16 | AC | 183 ms
20,480 KB |
testcase_17 | AC | 274 ms
29,824 KB |
testcase_18 | AC | 41 ms
7,680 KB |
testcase_19 | AC | 196 ms
20,864 KB |
testcase_20 | AC | 311 ms
37,376 KB |
testcase_21 | AC | 45 ms
8,064 KB |
testcase_22 | AC | 537 ms
52,352 KB |
testcase_23 | AC | 115 ms
14,720 KB |
testcase_24 | AC | 54 ms
8,960 KB |
testcase_25 | AC | 3 ms
6,944 KB |
testcase_26 | AC | 390 ms
44,160 KB |
testcase_27 | AC | 513 ms
53,760 KB |
testcase_28 | AC | 327 ms
32,256 KB |
testcase_29 | AC | 90 ms
12,160 KB |
testcase_30 | AC | 167 ms
20,736 KB |
testcase_31 | AC | 103 ms
13,184 KB |
testcase_32 | AC | 669 ms
61,184 KB |
testcase_33 | AC | 2 ms
6,940 KB |
testcase_34 | AC | 1 ms
6,940 KB |
testcase_35 | AC | 2 ms
6,940 KB |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/set:63, from /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/x86_64-pc-linux-gnu/bits/stdc++.h:158, from main.cpp:1: In member function 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]', inlined from 'int main()' at main.cpp:77:15: /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bits/stl_set.h:687:26: warning: 'e' may be used uninitialized [-Wmaybe-uninitialized] 687 | { return _M_t.erase(__x); } | ~~~~~~~~~~^~~~~ main.cpp: In function 'int main()': main.cpp:56:10: note: 'e' was declared here 56 | ll e; | ^ In member function 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>]', inlined from 'int main()' at main.cpp:54:15: /home/linuxbrew/.linuxbrew/Cellar/gcc/13.2.0/include/c++/13/bits/stl_set.h:687:26: warning: 'e' may be used uninitialized [-Wmaybe-uninitialized] 687 | { return _M_t.erase(__x); } | ~~~~~~~~~~^~~~~ main.cpp: In function 'int main()': main.cpp:33:10: note: 'e' was declared here 33 | ll e; | ^
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; using P=pair<ll,ll>; int main(){ ll h,w; cin>>h>>w; vector<vector<ll>> a(h,vector<ll>(w)); for(ll i=0;i<h;i++){ for(ll j=0;j<w;j++){ cin>>a[i][j]; } } vector<vector<ll>> co(h,vector<ll>(w,-1)); co[0][0]=1; co[h-1][w-1]=0; vector<ll> dx={0,0,-1,1}; vector<ll> dy={-1,1,0,0}; set<ll> k1,k2; map<ll,P> rev; k1.insert(a[0][1]); k1.insert(a[1][0]); k2.insert(a[h-2][w-1]); k2.insert(a[h-1][w-2]); for(ll i=0;i<h;i++){ for(ll j=0;j<w;j++){ rev[a[i][j]]=P(i,j); } } for(ll i=0;;i++){ if(i%2==0){ ll e; for(auto num:k1){ auto [x,y]=rev[num]; if(co[x][y]==-1){ co[x][y]=1; for(ll j=0;j<4;j++){ ll nx=x+dx[j]; ll ny=y+dy[j]; if(0<=nx&&nx<h&&0<=ny&&ny<w){ if(co[nx][ny]==-1){ k1.insert(a[nx][ny]); }else if(co[nx][ny]==0){ cout<<i+1<<endl; exit(0); } } } e=num; break; } } k1.erase(e); }else{ ll e; for(auto num:k2){ auto [x,y]=rev[num]; if(co[x][y]==-1){ co[x][y]=0; for(ll j=0;j<4;j++){ ll nx=x+dx[j]; ll ny=y+dy[j]; if(0<=nx&&nx<h&&0<=ny&&ny<w){ if(co[nx][ny]==-1){ k2.insert(a[nx][ny]); }else if(co[nx][ny]==1){ cout<<i+1<<endl; exit(0); } } } e=num; break; } } k2.erase(e); } } }