제출 #659073

#제출 시각아이디문제언어결과실행 시간메모리
659073ansgarMecho (IOI09_mecho)C++17
73 / 100
216 ms16616 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define vi vector<int> #define vvi vector<vi> #define pii pair<int,int> #define vpii vector<pii> #define vvpii vector<vpii> #define vb vector<bool> #define vc vector<char> #define vvc vector<vc> #define vvb vector<vb> #define si set<int> #define mii map<int,int> const int mod=1e9+7; const int N=2e5+1; const int LN=LLONG_MAX/10; vvc L; int n,k; vvi Bees; vvi Bear; vpii BeesLoc; bool inside(int y,int x){ return (y>=0 and y<n and x>=0 and x<n and L[y][x]!='T'); } void bfsBees(){ queue<pii> Q; for(auto B : BeesLoc){ Q.push(B); Bees[B.first][B.second]=-1; } while(Q.size()){ auto B=Q.front(); int x=B.second; int y=B.first; Q.pop(); if(inside(y-1,x) and Bees[y-1][x]>Bees[y][x]+1){ Bees[y-1][x]=Bees[y][x]+1; Q.push({y-1,x}); } if(inside(y+1,x) and Bees[y+1][x]>Bees[y][x]+1){ Bees[y+1][x]=Bees[y][x]+1; Q.push({y+1,x}); } if(inside(y,x-1) and Bees[y][x-1]>Bees[y][x]+1){ Bees[y][x-1]=Bees[y][x]+1; Q.push({y,x-1}); } if(inside(y,x+1) and Bees[y][x+1]>Bees[y][x]+1){ Bees[y][x+1]=Bees[y][x]+1; Q.push({y,x+1}); } } } void bfsBear(int sy,int sx,int w){ queue<pii> Q; Q.push({sy,sx}); Bear[sy][sx]=0; while(Q.size()){ auto B=Q.front(); int x=B.second; int y=B.first; Q.pop(); if(inside(y-1,x) and Bear[y-1][x]>Bear[y][x]+1 and Bees[y-1][x]-((Bear[y][x]+1)/k)>=w){ Bear[y-1][x]=Bear[y][x]+1; Q.push({y-1,x}); } if(inside(y+1,x) and Bear[y+1][x]>Bear[y][x]+1 and Bees[y+1][x]-((Bear[y][x]+1)/k)>=w){ Bear[y+1][x]=Bear[y][x]+1; Q.push({y+1,x}); } if(inside(y,x-1) and Bear[y][x-1]>Bear[y][x]+1 and Bees[y][x-1]-((Bear[y][x]+1)/k)>=w){ Bear[y][x-1]=Bear[y][x]+1; Q.push({y,x-1}); } if(inside(y,x+1) and Bear[y][x+1]>Bear[y][x]+1 and Bees[y][x+1]-((Bear[y][x]+1)/k)>=w){ Bear[y][x+1]=Bear[y][x]+1; Q.push({y,x+1}); } } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>n>>k; L=vvc(n,vc(n)); Bear=vvi(n,vi(n,LN)); Bees=vvi(n,vi(n,LN)); int sx,sy,ex,ey; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>L[i][j]; if(L[i][j]=='M')sy=i,sx=j; if(L[i][j]=='D')ey=i,ex=j; if(L[i][j]=='H')BeesLoc.emplace_back(i,j); } } bfsBees(); int high=LN; int low=0; int res=-1; while(high>=low){ int mid=(high+low)/2; Bear=vvi(n,vi(n,LN)); bfsBear(sy,sx,mid); if(Bear[ey][ex]==LN)high=mid-1; else{ res=mid; low=mid+1; } } cout<<res; }

컴파일 시 표준 에러 (stderr) 메시지

mecho.cpp: In function 'int main()':
mecho.cpp:108:19: warning: 'ey' may be used uninitialized in this function [-Wmaybe-uninitialized]
  108 |         if(Bear[ey][ex]==LN)high=mid-1;
      |                   ^
mecho.cpp:108:23: warning: 'ex' may be used uninitialized in this function [-Wmaybe-uninitialized]
  108 |         if(Bear[ey][ex]==LN)high=mid-1;
      |                       ^
mecho.cpp:107:16: warning: 'sy' may be used uninitialized in this function [-Wmaybe-uninitialized]
  107 |         bfsBear(sy,sx,mid);
      |         ~~~~~~~^~~~~~~~~~~
mecho.cpp:107:16: warning: 'sx' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...