Submission #915218

# Submission time Handle Problem Language Result Execution time Memory
915218 2024-01-23T14:01:57 Z vjudge1 Patkice (COCI20_patkice) C++17
50 / 50
1 ms 600 KB
#include "bits/stdc++.h"
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long r, c;
    cin>>r>>c;
    vector<string> Mapa(r);
    for(long long i = 0; i < r; i++) cin>>Mapa[i];
    long long Inicio_fila, Inicio_columna, Final_fila, Final_columna;
    for(long long i = 0; i < r; i++){
        for(long long j = 0; j < c; j++){
            if(Mapa[i][j] == 'o'){
                Inicio_fila = i;
                Inicio_columna = j;
            }
            if(Mapa[i][j] == 'x'){
                Final_fila = i;
                Final_columna = j;
            }
        }
    }
    long long Contador = 9999999999999999;
    char Respuesta = 'G';
    long long Contante = 1;
    long long Fila = Inicio_fila;
    long long Columna = Inicio_columna + 1;
    while(1){
        //cout<<Fila<<" "<<Columna<<"\n";
        if(Fila == Final_fila and Columna == Final_columna){
            if(Contante < Contador){
                Contador = Contante;
                Respuesta = 'E';
            }
            break;
        }
        if(Fila == Inicio_fila and Columna == Inicio_columna) break;
        bool zd = 0;
        switch(Mapa[Fila][Columna]){
            case '>':
            Columna++;
            break;
            case '<':
            Columna--;
            break;
            case '^':
            Fila--;
            break;
            case 'v':
            Fila++;
            break;
            case '.':
            zd = 1;
            break;
        }
        Contante++;
        if(zd) break;
    }
    Contante = 1;
    Fila = Inicio_fila - 1;
    Columna = Inicio_columna;
    while(1){
        if(Fila == Final_fila and Columna == Final_columna){
            if(Contante < Contador){
                Contador = Contante;
                Respuesta = 'N';
            }
            break;
        }
        if(Fila == Inicio_fila and Columna == Inicio_columna) break;
        bool zd = 0;
        switch(Mapa[Fila][Columna]){
            case '>':
            Columna++;
            break;
            case '<':
            Columna--;
            break;
            case '^':
            Fila--;
            break;
            case 'v':
            Fila++;
            break;
            case '.':
            zd = 1;
            break;
        }
        Contante++;
        if(zd) break;
    }
    Contante = 1;
    Fila = Inicio_fila + 1;
    Columna = Inicio_columna;
    while(1){
        if(Fila == Final_fila and Columna == Final_columna){
            if(Contante < Contador){
                Contador = Contante;
                Respuesta = 'S';
            }
            break;
        }
        if(Fila == Inicio_fila and Columna == Inicio_columna) break;
        bool zd = 0;
        switch(Mapa[Fila][Columna]){
            case '>':
            Columna++;
            break;
            case '<':
            Columna--;
            break;
            case '^':
            Fila--;
            break;
            case 'v':
            Fila++;
            break;
            case '.':
            zd = 1;
            break;
        }
        Contante++;
        if(zd) break;
    }
    Contante = 1;
    Fila = Inicio_fila;
    Columna = Inicio_columna - 1;
    while(1){
        if(Fila == Final_fila and Columna == Final_columna){
            if(Contante < Contador){
                Contador = Contante;
                Respuesta = 'W';
            }
            break;
        }
        if(Fila == Inicio_fila and Columna == Inicio_columna) break;
        bool zd = 0;
        switch(Mapa[Fila][Columna]){
            case '>':
            Columna++;
            break;
            case '<':
            Columna--;
            break;
            case '^':
            Fila--;
            break;
            case 'v':
            Fila++;
            break;
            case '.':
            zd = 1;
            break;
        }
        Contante++;
        if(zd) break;
    }
    if(Respuesta == 'G') cout<<":(";
    else cout<<":)\n"<<Respuesta;
    return 0;
}

Compilation message

patkice.cpp: In function 'int main()':
patkice.cpp:129:43: warning: 'Final_columna' may be used uninitialized in this function [-Wmaybe-uninitialized]
  129 |         if(Fila == Final_fila and Columna == Final_columna){
      |                                   ~~~~~~~~^~~~~~~~~~~~~~~~
patkice.cpp:96:9: warning: 'Final_fila' may be used uninitialized in this function [-Wmaybe-uninitialized]
   96 |         if(Fila == Final_fila and Columna == Final_columna){
      |         ^~
patkice.cpp:127:13: warning: 'Inicio_columna' may be used uninitialized in this function [-Wmaybe-uninitialized]
  127 |     Columna = Inicio_columna - 1;
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
patkice.cpp:60:10: warning: 'Inicio_fila' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |     Fila = Inicio_fila - 1;
      |     ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct