Submission #54675

#TimeUsernameProblemLanguageResultExecution timeMemory
54675okaybody10Mecho (IOI09_mecho)C++98
100 / 100
242 ms52292 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; typedef pair<pii,int> piii; int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1}; int pre[2000][2000]; char mark[2000][2000]; int homex,homey; int s,sx,sy,N; bool test(int time) { bool reach[2005][2005]; memset(reach,0,sizeof(reach)); if(time * s >= pre[sx][sy]) return false; queue<piii> q; q.push(make_pair(make_pair(sx,sy),time*s)); reach[sx][sy]=1; while(!q.empty()) { int x=q.front().first.first; int y=q.front().first.second; int dis=q.front().second; if(mark[x][y]=='D') return true; q.pop(); for(int c=0;c<4;c++) { int cx=x+dx[c],cy=y+dy[c]; if(cx<0 || cx>=N || cy<0 || cy>=N || pre[cx][cy]<=dis+1 || mark[cx][cy]=='T' || reach[cx][cy]) continue; reach[cx][cy]=true; q.push(make_pair(make_pair(cx,cy),dis+1)); } } return false; } int main() { memset(pre,-1,sizeof(pre)); scanf("%d %d",&N,&s); queue<pii> que; for(int i=0;i<N;i++)scanf("%s",mark[i]); for(int i=0;i<N;i++){ for(int j=0;j<N;j++) { if(mark[i][j]=='M') sx=i,sy=j,mark[i][j]='G'; if(mark[i][j]=='D') homex=i,homey=j; if(mark[i][j]=='H') que.push(make_pair(i,j)),pre[i][j]=0; } } pre[homex][homey]=N*N*s; while(!que.empty()) { int x=que.front().first; int y=que.front().second; int dis=pre[x][y]; que.pop(); for(int c=0;c<4;c++) { int cx=x+dx[c],cy=y+dy[c]; if(cx<0 || cx>=N || cy<0 || cy>=N || pre[cx][cy]!=-1 || mark[cx][cy]!='G') continue; pre[cx][cy]=dis+s; que.push(make_pair(cx,cy)); } } int low=0,high=N*N*2,ans=-1; for(;low<high;) { int mid=(low+high)/2; if(test(mid)) ans=max(ans,mid),low=mid+1; else high=mid; } return !printf("%d",ans); }

Compilation message (stderr)

mecho.cpp: In function 'int main()':
mecho.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&N,&s);
     ~~~~~^~~~~~~~~~~~~~~
mecho.cpp:40:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=0;i<N;i++)scanf("%s",mark[i]);
                         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...