# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
313756 | Massiosare | Mecho (IOI09_mecho) | C++14 | 274 ms | 6392 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 <iostream>
#include <queue>
#define MAX 805
using namespace std;
struct coords{
int fil;
int col;
int nivel;
int temporal;
};
int best;
int maxpro;
coords pro,start;
int n,steps;
char mat[MAX][MAX];
bool visitados[MAX][MAX];
int valores[MAX][MAX];
queue <coords> q,q2;
void add(coords temp){
coords temp2=temp;
temp2.nivel++;
//col+
temp2.col++;
q.push(temp2);
temp2.col--;
//fil+
temp2.fil++;
q.push(temp2);
temp2.fil--;
//col-
temp2.col--;
q.push(temp2);
temp2.col++;
//fil-
temp2.fil--;
q.push(temp2);
temp2.fil++;
return;
}
void add2(coords temp){
coords temp2=temp;
temp2.temporal++;
if(temp2.temporal%steps==0){
temp2.nivel++;
}
//col+
temp2.col++;
q2.push(temp2);
temp2.col--;
//fil+
temp2.fil++;
q2.push(temp2);
temp2.fil--;
//col-
temp2.col--;
q2.push(temp2);
temp2.col++;
//fil-
temp2.fil--;
q2.push(temp2);
temp2.fil++;
return;
}
bool busca2(){
while(!q2.empty()){
coords temp=q2.front();
q2.pop();
if(temp.col<1||temp.col>n||temp.fil>n||temp.fil<1){
continue;
}
if(visitados[temp.fil][temp.col]==1||mat[temp.fil][temp.col]=='T'){
continue;
}
else {
visitados[temp.fil][temp.col]=1;
}
if(valores[temp.fil][temp.col]<=temp.nivel){
continue;
}
if(mat[temp.fil][temp.col]=='D'){
if(valores[temp.fil][temp.col]<=temp.nivel){
return 0;
}
return 1;
}
add2(temp);
}
return 0;
}
void binaria(int ini,int fin){
while(ini<=fin){
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
visitados[i][j]=0;
}
}
while(!q2.empty()){
q2.pop();
}
int mid=(ini+fin)/2;
start.nivel=mid;
q2.push(start);
bool x=busca2();
if(x==1){
best=mid;
ini=mid+1;
}
else {
fin=mid-1;
}
}
cout << best;
}
void busca(){
while(!q.empty()){
coords temp=q.front();
q.pop();
if(temp.col<1||temp.col>n||temp.fil>n||temp.fil<1){
continue;
}
if(visitados[temp.fil][temp.col]==0){
valores[temp.fil][temp.col]=temp.nivel;
visitados[temp.fil][temp.col]=1;
}
else {
continue;
}
if(mat[temp.fil][temp.col]=='M'){
maxpro=valores[temp.fil][temp.col];
}
add(temp);
}
return;
}
int main()
{
cin >> n >> steps;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
cin >> mat[i][j];
if(mat[i][j]=='H'){
pro.fil=i;
pro.col=j;
q.push(pro);
}
if(mat[i][j]=='M'){
start.fil=i;
start.col=j;
start.nivel=0;
}
}
}
busca();
binaria(1,maxpro);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |