제출 #1329283

#제출 시각아이디문제언어결과실행 시간메모리
1329283moondarksideMecho (IOI09_mecho)C++20
11 / 100
1095 ms131072 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long



std::vector<vector<int>>map;
std::vector<vector<int>>Time;

bool CheckPossible(int ST,int s,pair<int,int> Start,vector<vector<int>> Time,int n){
    std::queue<pair<pair<int,int>,int>>Expand;
    if(Time[Start.first][Start.second]<=ST){
        return false;
    }
    Expand.push({{Start.first,Start.second},0});
    while(!Expand.empty()){
        
        
        int x=Expand.front().first.first;
        int y=Expand.front().first.second;
        int t=Expand.front().second;
        

        
        if(x>0 && Time[x-1][y]>ST+(t/s)){
            Expand.push({{x-1,y},t+1});
        }
        if(x<n-1 && Time[x+1][y]>ST+(t/s)){
            Expand.push({{x+1,y},t+1});
        }
        
        if(y>0 && Time[x][y-1]>ST+(t/s)){
            Expand.push({{x,y-1},t+1});
        }
        if(y<n-1 && Time[x][y+1]>ST+(t/s)){
            Expand.push({{x,y+1},t+1});
        }
        
        if(Time[x][y]==100000){
            return true;
        }
        

        Expand.pop();
        
        
    }
    return false;
    
    



}

signed main(){
    
    int n,s;
    cin>>n>>s;
    pair<int,int> start;
    pair<int,int> end;
    Time=vector<vector<int>>(n,vector<int>(n,-1));
    std::queue<pair<pair<int,int>,int>>Expand;
    
    for(int x=0;x<n;x++){
        
        for(int y=0;y<n;y++){
        
            char c;
            cin>>c;
            if(c=='T'){
                Time[x][y]=0;
            }
            if(c=='M'){
                start={x,y};
            }
            if(c=='D'){
                end={x,y};
                Time[x][y]=100000;
            }
            if(c=='H'){
                Time[x][y]=0;
                Expand.push({{x,y},0});
            }
        
        }
    }
    
    while(!Expand.empty()){
        
        int x=Expand.front().first.first;
        int y=Expand.front().first.second;
        int t=Expand.front().second;
        
        if(x>0 && Time[x-1][y]==-1){
            Time[x-1][y]=t+1;
            Expand.push({{x-1,y},t+1});
        }
        if(x<n-1 && Time[x+1][y]==-1){
            Time[x+1][y]=t+1;
            Expand.push({{x+1,y},t+1});
        }
        
        if(y>0 && Time[x][y-1]==-1){
            Time[x][y-1]=t+1;
            Expand.push({{x,y-1},t+1});
        }
        if(y<n-1 && Time[x][y+1]==-1){
            Time[x][y+1]=t+1;
            Expand.push({{x,y+1},t+1});
        }
        
        Expand.pop();
    }
    
    
    
   int m=0;
    for(int i=0;i<800;i++){
        if(CheckPossible(i,s,start,Time,n)){
            m=i+1;
        }
    }
    cout<<m-1<<endl;
    return 0;
    
    
    
}
#Verdict Execution timeMemoryGrader output
Fetching results...