제출 #998326

#제출 시각아이디문제언어결과실행 시간메모리
998326AtinaRMecho (IOI09_mecho)C++14
100 / 100
159 ms5336 KiB
#include <bits/stdc++.h> using namespace std; const int MAX=810; const int INF=(1<<30); int di[4]={0,0,-1,1}; int dj[4]={1,-1,0,0}; int n,s; char mat[MAX][MAX]; int timebees[MAX][MAX]; bool visbees[MAX][MAX]; bool vis[MAX][MAX]; vector<pair<int,int> > hiveinitial; vector<pair<int,int> > homeinitial; int mi,mj; int homei,homej; bool validBees(int i, int j) { if(i<0 || i>=n || j<0 || j>=n || mat[i][j]=='T'||mat[i][j]=='D'|| mat[i][j]=='H'|| visbees[i][j])return false; return true; } bool validBear(int i, int j) { if(i<0 || i>=n || j<0 || j>=n || mat[i][j]!='G' || vis[i][j])return false; return true; } void bfsBees() { queue<pair<int,int> > q; for(int i=0; i<hiveinitial.size(); i++) { int x=hiveinitial[i].first; int y=hiveinitial[i].second; q.push({x,y}); visbees[x][y]=true; timebees[x][y]=0; } while(!q.empty()) { pair<int,int> curr=q.front(); q.pop(); int x=curr.first; int y=curr.second; for(int k=0; k<4; k++) { int newi=x+di[k]; int newj=y+dj[k]; if(validBees(newi,newj)) { q.push({newi,newj}); timebees[newi][newj]=timebees[x][y]+1; visbees[newi][newj]=true; } } } return; } bool bearreached(int mechodis, int beedis) { return mechodis/s<beedis; } bool canReach(int secs) { queue<pair<int,int> > q; q.push({mi,mj}); if(timebees[mi][mj]<=secs) { return false; } memset(vis,false,sizeof(vis)); vis[mi][mj]=true; queue<int> steps; steps.push(0); while(!q.empty()) { pair<int,int> curr=q.front(); int x=curr.first; int y=curr.second; int currstep=steps.front(); steps.pop(); q.pop(); for(int k=0; k<4; k++) { int newi=x+di[k]; int newj=y+dj[k]; if(mat[newi][newj]=='D')return true; if(validBear(newi,newj)) { if(bearreached(currstep+1,timebees[newi][newj]-secs)) { q.push({newi,newj}); steps.push(currstep+1); vis[newi][newj]=true; } } } } for(int k=0; k<4; k++) { int newi=homei+di[k]; int newj=homej+dj[k]; if(validBear(newi,newj)&& vis[newi][newj])return true; } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>s; for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { cin>>mat[i][j]; if(mat[i][j]=='H') { hiveinitial.push_back({i,j}); } if(mat[i][j]=='M') { mi=i; mj=j; } if(mat[i][j]=='D') { homei=i; homej=j; } } } bfsBees(); int b=0; int e=n*n; while(b<=e) { int mid=(b+e)/2; if(canReach(mid)) { b=mid+1; } else { e=mid-1; } } cout<<b-1<<endl; return 0; }

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

mecho.cpp: In function 'void bfsBees()':
mecho.cpp:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i=0; i<hiveinitial.size(); i++)
      |                  ~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...