#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct info{
int fila;
int columna;
int nivel;
char letra;
};
string bfs(int n, int m, vector<vector<char>>tablero){
int nivelactual=0;
string s="";
s+=tablero[0][0];
queue<info>cola;
vector<vector<bool>>visto(n, vector<bool>(m, false));
info primero;
primero.fila=1;
primero.columna=0;
primero.nivel=1;
primero.letra=s[0];
cola.push(primero);
primero.fila=0;
primero.columna=1;
cola.push(primero);
while (!cola.empty()){
int i_actual=cola.front().fila;
int j_actual=cola.front().columna;
if (i_actual==n or j_actual==m or visto[i_actual][j_actual]==true){
cola.pop();
continue;
}visto[i_actual][j_actual]=true;
if (cola.front().nivel!=nivelactual){
nivelactual++;
s+='z';
}if (s[nivelactual-1]==cola.front().letra){
if (s[nivelactual]>=tablero[i_actual][j_actual]){
s[nivelactual]=tablero[i_actual][j_actual];
info casilla;
casilla.fila=i_actual+1;
casilla.columna=j_actual;
casilla.nivel=nivelactual+1;
casilla.letra=s[nivelactual];
cola.push(casilla);
casilla.fila--;
casilla.columna++;
cola.push(casilla);
}
}cola.pop();
}return s;
}
int main(){
int n, m;
cin>>n>>m;
vector<vector<char>>tablero(n, vector<char>(m));
for (int i=0; i<n; i++){
for (int j=0; j<m; j++) cin>>tablero[i][j];
}cout<<bfs(n, m, tablero)<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
6 |
Incorrect |
8 ms |
940 KB |
Output isn't correct |
7 |
Incorrect |
43 ms |
3312 KB |
Output isn't correct |
8 |
Incorrect |
126 ms |
9004 KB |
Output isn't correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
11 |
Incorrect |
4 ms |
604 KB |
Output isn't correct |
12 |
Incorrect |
11 ms |
1280 KB |
Output isn't correct |
13 |
Incorrect |
7 ms |
856 KB |
Output isn't correct |
14 |
Incorrect |
140 ms |
9016 KB |
Output isn't correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
62 ms |
3924 KB |
Output is correct |