Submission #916421

# Submission time Handle Problem Language Result Execution time Memory
916421 2024-01-25T20:23:01 Z svaz Patkice (COCI20_patkice) C++14
30 / 50
1 ms 348 KB
#include<bits/stdc++.h>
using namespace std;
int main(){
    int r,s,inx,iny;
    cin>>r>>s;
    char matriz[r][s];
    for(int i=0;i<r;i++){
        for(int j=0;j<s;j++){
            cin>>matriz[i][j];
            if(matriz[i][j]=='o'){
                inx=i;
                iny=j;
            }
        }
    }
    int x,y,cp=0,ans=(r*s)+1;
    char opt='Z';
    x=inx;
    y=iny-1;
    vector< vector<bool> > visitados(r,vector<bool> (s,false));
    while(matriz[x][y]!='.' && matriz[x][y]!='x' && x>=0 && x<r && y>=0 && y<s && !visitados[x][y]){
        visitados[x][y]=true;
        cp++;
        if(matriz[x][y]=='>')y++;
        if(matriz[x][y]=='<')y--;
        if(matriz[x][y]=='^')x--;
        if(matriz[x][y]=='v')x++;
    }
    if(x>=0 && x<r && y>=0 && y<s){
        if(matriz[x][y]=='x'){
            if(cp<ans){
                ans=cp;
                opt='W';
            }
            if(cp==ans){
                opt=min(opt,'W');
            }
        }
    }
    x=inx-1;
    y=iny;
    cp=0;
    while(matriz[x][y]!='.' && matriz[x][y]!='x' && x>=0 && x<r && y>=0 && y<s && !visitados[x][y]){
                visitados[x][y]=true;
        cp++;
        if(matriz[x][y]=='>')y++;
        if(matriz[x][y]=='<')y--;
        if(matriz[x][y]=='^')x--;
        if(matriz[x][y]=='v')x++;
    }
    if(x>=0 && x<r && y>=0 && y<s){
        if(matriz[x][y]=='x'){
            if(cp<ans){
                ans=cp;
                opt='N';
            }
            if(cp==ans){
                opt=min(opt,'N');
            }
        }
    }
    x=inx;
    y=iny+1;
    cp=0;
    while(matriz[x][y]!='.' && matriz[x][y]!='x' && x>=0 && x<r && y>=0 && y<s && !visitados[x][y]){
                    visitados[x][y]=true;

        cp++;
        if(matriz[x][y]=='>')y++;
        if(matriz[x][y]=='<')y--;
        if(matriz[x][y]=='^')x--;
        if(matriz[x][y]=='v')x++;
    }
    if(x>=0 && x<r && y>=0 && y<s){
        if(matriz[x][y]=='x'){
            if(cp<ans){
                ans=cp;
                opt='E';
            }
            if(cp==ans){
                opt=min(opt,'E');
            }
        }
    }
    x=inx+1;
    y=iny;
    cp=0;
    while(matriz[x][y]!='.' && matriz[x][y]!='x' && x>=0 && x<r && y>=0 && y<s && !visitados[x][y]){
                        visitados[x][y]=true;
        cp++;
        if(matriz[x][y]=='>')y++;
        if(matriz[x][y]=='<')y--;
        if(matriz[x][y]=='^')x--;
        if(matriz[x][y]=='v')x++;
    }
    if(x>=0 && x<r && y>=0 && y<s){
        if(matriz[x][y]=='x'){
            if(cp<ans){
                ans=cp;
                opt='S';
            }
            if(cp==ans){
                opt=min(opt,'S');
            }
        }
    }
    if(opt=='Z')cout<<":(\n";
    else{
      cout<<":)\n";
      cout<<opt<<"\n";
    }
    return 0;
}

Compilation message

patkice.cpp: In function 'int main()':
patkice.cpp:65:65: warning: 'inx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   65 |     while(matriz[x][y]!='.' && matriz[x][y]!='x' && x>=0 && x<r && y>=0 && y<s && !visitados[x][y]){
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
patkice.cpp:63:6: warning: 'iny' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |     y=iny+1;
      |     ~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -