제출 #659065

#제출 시각아이디문제언어결과실행 시간메모리
659065ansgarMecho (IOI09_mecho)C++17
17 / 100
87 ms22328 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; vvpii p; 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){ queue<pii> Q; Q.push({sy,sx}); Bear[sy][sx]=0; p[sy][sx]={sy,sx}; 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){ Bear[y-1][x]=Bear[y][x]+1; p[y-1][x]={y,x}; Q.push({y-1,x}); } if(inside(y+1,x) and Bear[y+1][x]>Bear[y][x]+1){ Bear[y+1][x]=Bear[y][x]+1; p[y+1][x]={y,x}; Q.push({y+1,x}); } if(inside(y,x-1) and Bear[y][x-1]>Bear[y][x]+1){ Bear[y][x-1]=Bear[y][x]+1; p[y][x-1]={y,x}; Q.push({y,x-1}); } if(inside(y,x+1) and Bear[y][x+1]>Bear[y][x]+1){ Bear[y][x+1]=Bear[y][x]+1; p[y][x+1]={y,x}; 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)); p=vvpii(n,vpii(n,{-1,-1})); 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(); bfsBear(sy,sx); int sol=LN; int aux=ey; if(p[ex][ey].first==-1){ cout<<"-1"; return 0; } ey=p[ey][ex].first; ex=p[aux][ex].second; while(p[ey][ex].first!=ey or p[ey][ex].second!=ex){ //cout<<ex+1<<" "<<n-ey<<endl; //cout<<Bear[ey][ex]<<" "<<Bees[ey][ex]<<endl<<endl; sol=min(sol,Bees[ey][ex]-((Bear[ey][ex]-1)/k)); aux=ey; ey=p[ey][ex].first; ex=p[aux][ex].second; } cout<<sol; }

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

mecho.cpp: In function 'int main()':
mecho.cpp:112:16: warning: 'ey' may be used uninitialized in this function [-Wmaybe-uninitialized]
  112 |     if(p[ex][ey].first==-1){
      |                ^
mecho.cpp:112:12: warning: 'ex' may be used uninitialized in this function [-Wmaybe-uninitialized]
  112 |     if(p[ex][ey].first==-1){
      |            ^
mecho.cpp:109:12: warning: 'sy' may be used uninitialized in this function [-Wmaybe-uninitialized]
  109 |     bfsBear(sy,sx);
      |     ~~~~~~~^~~~~~~
mecho.cpp:109:12: warning: 'sx' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...