Submission #914785

# Submission time Handle Problem Language Result Execution time Memory
914785 2024-01-22T16:48:16 Z vjudge1 Patkice (COCI20_patkice) C++17
0 / 50
1000 ms 348 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
#define MOD 1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FIN "\n"
#define REP(i,a,b) for(int i=a;i<b;i++)
#define ALL(x) x.begin(),x.end();
typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
int r,s;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin >> r >> s;
    char corr[r][s];
    int posi;
    int posj;
    for(int i=0;i<r;i++){
        for(int j=0;j<s;j++){
            cin >> corr[i][j];
            if(corr[i][j]=='o'){
                posi=i;
                posj=j;
            }
        }
    }
    int i=posi;
    int j=posj+1;
    int mini=1e9;
    int con=0;
    bool xd=false;
    char res='.';
    while(i>=0 && i<r && j>=0 && j<s){
        con++;
        if(corr[i][j]=='^'){
            i--;
        }else if(corr[i][j]=='v'){
            i++;
        }else if(corr[i][j]=='<'){
            j--;
        }else if(corr[i][j]=='>'){
            j++;
        }else if(corr[i][j]=='.'){
            break;
        }else if(corr[i][j]=='x'){
            xd=true;
            break;
        }
    }
    if(xd){
        res='E';
        mini=con;
    }
    i=posi-1;
    j=posj;
    con=0;
    xd=false;
    while(i>=0 && i<r && j>=0 && j<s){
        con++;
        if(corr[i][j]=='^'){
            i--;
        }else if(corr[i][j]=='v'){
            i++;
        }else if(corr[i][j]=='<'){
            j--;
        }else if(corr[i][j]=='>'){
            j++;
        }else if(corr[i][j]=='.'){
            break;
        }else if(corr[i][j]=='x'){
            xd=true;
            break;
        }
    }
    if(xd){
        if(con<mini){
            mini=con;
            res='N';
        }
    }
    i=posi+1;
    j=posj;
    con=0;
    xd=false;
    while(i>=0 && i<r && j>=0 && j<s){
        con++;
        if(corr[i][j]=='^'){
            i--;
        }else if(corr[i][j]=='v'){
            i++;
        }else if(corr[i][j]=='<'){
            j--;
        }else if(corr[i][j]=='>'){
            j++;
        }else if(corr[i][j]=='.'){
            break;
        }else if(corr[i][j]=='x'){
            xd=true;
            break;
        }
    }
    if(xd){
        if(con<mini){
            mini=con;
            res='S';
        }
    }
    i=posi;
    j=posj-1;
    con=0;
    xd=false;
    while(i>=0 && i<r && j>=0 && j<s){
        con++;
        if(corr[i][j]=='^'){
            i--;
        }else if(corr[i][j]=='v'){
            i++;
        }else if(corr[i][j]=='<'){
            j--;
        }else if(corr[i][j]=='>'){
            j++;
        }else if(corr[i][j]=='.'){
            break;
        }else if(corr[i][j]=='x'){
            xd=true;
            break;
        }
    }
    if(xd){
        if(con<mini){
            mini=con;
            res='W';
        }
    }
    if(res!='.'){
        cout << ":)\n";
        cout << res; 
    }else{
        cout << ":(";
    }
}

Compilation message

patkice.cpp: In function 'int main()':
patkice.cpp:43:23: warning: 'posi' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |     while(i>=0 && i<r && j>=0 && j<s){
      |           ~~~~~~~~~~~~^~~~~~~
patkice.cpp:119:6: warning: 'posj' may be used uninitialized in this function [-Wmaybe-uninitialized]
  119 |     j=posj-1;
      |     ~^~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1018 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1014 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -