結果
| 問題 |
No.2731 Two Colors
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-19 22:59:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,020 ms / 3,000 ms |
| コード長 | 1,691 bytes |
| コンパイル時間 | 2,592 ms |
| コンパイル使用メモリ | 211,908 KB |
| 最終ジャッジ日時 | 2025-02-21 05:14:51 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
コンパイルメッセージ
In file included from /usr/include/c++/13/set:63,
from /usr/include/x86_64-linux-gnu/c++/13/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:
/usr/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:
/usr/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);
}
}
}