# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
60037 | nvmdava | Mecho (IOI09_mecho) | C++17 | 1093 ms | 27016 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
using namespace std;
int n,s;
int t[802][802];
char c[802][802];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
bool pos(int x,int y, int now){
for(int i = 0; i < 4; i++){
if(c[x + dx[i]][y + dy[i]]=='D'){
return 1;
}
if(c[x + dx[i]][y + dy[i]]=='G'&&t[x + dx[i]][y + dy[i]] > now + 1){
c[x + dx[i]][y + dy[i]]=='T';
if(pos(x + dx[i],y + dy[i],now+1)){
c[x + dx[i]][y + dy[i]]=='G';
return 1;
};
c[x + dx[i]][y + dy[i]]=='G';
}
}
return 0;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int i,j,xx,yy;
cin>>n>>s;
queue<pair<int, int > > q;
for(i = 1; i <= n; i++){
for(j = 1; j <= n; j++){
cin>>c[i][j];
if(c[i][j]=='H'){
q.push(mp(i,j));
} else if(c[i][j]=='M'){
xx=i;
yy=j;
}
}
}
int x,y;
while(!q.empty()){
x=q.front().ff;
y=q.front().ss;
q.pop();
for(i=0;i<4;i++){
if(c[x + dx[i]][y + dy[i]]=='G'&&t[x + dx[i]][y + dy[i]]==0){
t[x + dx[i]][y + dy[i]] = t[x][y]+s;
q.push(mp(x + dx[i] , y + dy[i]));
}
}
}
int l = -1 , r = 1e9,m;
while(l + 1 != r){
m = (l + r) / 2;
if(pos(xx,yy,m)){
l = m;
} else {
r = m;
}
}
cout<<l/s;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |