제출 #643382

#제출 시각아이디문제언어결과실행 시간메모리
643382AtinaRMecho (IOI09_mecho)C++14
17 / 100
40 ms7636 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]; int beartime[MAX][MAX]; bool visbees[MAX][MAX]; bool visbear[MAX][MAX]; vector<pair<int,int> > hiveinitial; vector<pair<int,int> > homeinitial; int mi,mj; int homei,homej; bool valid_move(int i, int j) { if(i<0 || i>n || j<0 || j>n || mat[i][j]=='T' || mat[i][j]=='D' )return false; return true; } bool bearReach(int a, int b) { return a/s<b; } 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; visbees[x][y]=true; timebees[x][y]=0; q.push({x,y}); } while(!q.empty()) { pair<int,int> curr=q.front(); int x=curr.first; int y=curr.second; q.pop(); for(int k=0; k<4; k++) { int newi=x+di[k]; int newj=y+dj[k]; if(valid_move(newi,newj)&& !visbees[newi][newj]) { visbees[newi][newj]=true; q.push({newi,newj}); timebees[newi][newj]=timebees[x][y]+1; } } } return; } bool bfsBear(int eatTime) { queue<pair<int,int> > q; q.push({mi,mj}); visbear[mi][mj]=true; if(eatTime>=timebees[mi][mj])return false; 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=di[k]+x; int newj=dj[k]+y; if(valid_move(newi,newj) && !visbear[newi][newj]&& bearReach(beartime[x][y]+1,timebees[newi][newj]-eatTime)) { visbear[newi][newj]=true; q.push({newi,newj}); beartime[newi][newj]=beartime[x][y]+1; } } } for(int k=0; k<4; k++) { int newi=homei+di[k]; int newj=homej+dj[k]; if(valid_move(newi,newj) && bearReach(beartime[newi][newj],timebees[newi][newj]-eatTime) && visbear[newi][newj])return true; } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>s; memset(beartime,0,sizeof(beartime)); 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(bfsBear(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...