# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1031696 | ezzzay | Mecho (IOI09_mecho) | C++14 | 1098 ms | 4572 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>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define int long long
const int N=1000;
char arr[N][N];
bool vis[N][N];
int xx[4]={1,-1,0,0};
int yy[4]={0,0,-1,1};
int sx,sy,fx,fy;
char brr[N][N],crr[N][N];
int n,s;
void dfs(int y, int x){
vis[y][x]=1;
for(int i=0;i<4;i++){
if((brr[y+yy[i]][x+xx[i]]=='G' or brr[y+yy[i]][x+xx[i]]=='D') and vis[y+yy[i]][x+xx[i]]==0 ){
dfs(y+yy[i],x+xx[i]);
}
}
}
bool check(int t){
int h=t;
while(h--){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
crr[i][j]=brr[i][j];
vis[i][j]=0;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int k=0;k<4;k++){
if(crr[i+yy[k]][j+xx[k]]=='G' and crr[i][j]=='H'){
brr[i+yy[k]][j+xx[k]]='H';
}
}
}
}
}
vis[sy][sx]=1;
dfs(sy,sx);
return vis[fy][fx];
}
signed main(){
cin>>n>>s;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>arr[i][j];
if(arr[i][j]=='M'){
sy=i;
sx=j;
}
if(arr[i][j]=='D'){
fy=i;
fx=j;
}
}
}
int lo=0,hi=10000;
while(hi>=lo){
int mid=(hi+lo)/2;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
brr[i][j]=arr[i][j];
}
}
if(check(mid)){
lo=mid+1;
}
else{
hi=mid-1;
}
}
cout<<hi-2;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |