답안 #916441

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
916441 2024-01-25T23:15:47 Z svaz Patkice (COCI20_patkice) C++14
50 / 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,ans=(r*s)+10;
    char opt='Z';
    x=inx;
    y=iny+1;
    cp=0;
    while(matriz[x][y]!='.' && matriz[x][y]!='x' && matriz[x][y]!='o' && x>=0 && x<r && y>=0 && y<s){
       // cout<<x<<" "<<y<<endl;
        cp++;
        if(matriz[x][y]=='>')y++;
        else if(matriz[x][y]=='<')y--;
        else if(matriz[x][y]=='^')x--;
        else 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';
               // cout<<"e:"<<cp<<endl;
            }
        }
    }
    x=inx-1;
    y=iny;
    cp=0;
    while(matriz[x][y]!='.' && matriz[x][y]!='x' && matriz[x][y]!='o' && x>=0 && x<r && y>=0 && y<s){
        cp++;
        if(matriz[x][y]=='>')y++;
        else if(matriz[x][y]=='<')y--;
        else if(matriz[x][y]=='^')x--;
        else 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';
                               // cout<<"n:"<<cp<<endl;
            }

        }
    }
    x=inx+1;
    y=iny;
    cp=0;
    while(matriz[x][y]!='.' && matriz[x][y]!='x' && matriz[x][y]!='o' && x>=0 && x<r && y>=0 && y<s){
       // cout<<x<<" "<<y<<endl;
        cp++;
        if(matriz[x][y]=='>')y++;
        else if(matriz[x][y]=='<')y--;
        else if(matriz[x][y]=='^')x--;
        else 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';
                                //cout<<"s:"<<cp<<endl;

            }

        }
    }
    x=inx;
    y=iny-1;
    cp=0;
    while(matriz[x][y]!='.' && matriz[x][y]!='x' && matriz[x][y]!='o' && x>=0 && x<r && y>=0 && y<s){
        cp++;
        if(matriz[x][y]=='>')y++;
        else if(matriz[x][y]=='<')y--;
        else if(matriz[x][y]=='^')x--;
        else 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';
                              //  cout<<"w:"<<cp<<endl;
            }
        }
    }

    if(opt=='Z')cout<<":(\n";
    else{
      cout<<":)\n";
      cout<<opt<<"\n";
    }
    return 0;
}

Compilation message

patkice.cpp: In function 'int main()':
patkice.cpp:58:6: warning: 'inx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   58 |     x=inx+1;
      |     ~^~~~~~
patkice.cpp:61:22: warning: 'iny' may be used uninitialized in this function [-Wmaybe-uninitialized]
   61 |     while(matriz[x][y]!='.' && matriz[x][y]!='x' && matriz[x][y]!='o' && x>=0 && x<r && y>=0 && y<s){
      |           ~~~~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 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 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 0 ms 348 KB Output is correct
6 Correct 0 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
11 Correct 0 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 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct