Submission #851375

# Submission time Handle Problem Language Result Execution time Memory
851375 2023-09-19T17:08:34 Z vjudge1 Patkice (COCI20_patkice) C++17
50 / 50
1 ms 412 KB
#ifndef Local
    #pragma GCC optimize("O3,unroll-loops")
    #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define lim 1000000
#define till 1000001
// # of primes till 1e6 = 7e4
using namespace std;
using pii = array<int,2>;
const int mod=1000000007ll;

string s[1000];
int n,m;

int dfs(int i,int j){
    if(s[i][j]=='x'){
        return 0;
    }
    if(s[i][j]=='.'||s[i][j]=='o'){
        return -1;
    }
    int res=-1;
    switch (s[i][j]){
    case '^':
        res=dfs(i-1,j);
        break;
    case 'v':
        res=dfs(i+1,j);
        break;
    case '<':
        res=dfs(i,j-1);
        break;
    case '>':
        res=dfs(i,j+1);
        break;
    }
    if(res==-1)return -1;
    else return res+1;
}

void solve(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    int si,sj;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i][j]=='o'){
                si=i;
                sj=j;
                break;
            }
        }
    }
    int resu=-1,resd=-1,resl=-1,resr=-1;
    resu=dfs(si-1,sj);
    resd=dfs(si+1,sj);
    resl=dfs(si,sj-1);
    resr=dfs(si,sj+1);
    int ansi=INT_MAX;
    for(int i:{resu,resd,resl,resr}){
        if(0<=i){
            ansi=min(ansi,i);
        }
    }
    if(ansi==INT_MAX){
        cout<<":(\n";
        return;
    }
    cerr<<ansi<<"\n";
    cerr<<resu<<" "<<resd<<" "<<resl<<" "<<resr<<"\n";
    cout<<":)\n";
    if(resr==ansi){
        cout<<"E\n";
    }else if(resu==ansi){
        cout<<"N\n";
    }else if(resd==ansi){
        cout<<"S\n";
    }else{
        cout<<"W\n";
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
#ifdef Local  
    freopen("in","r",stdin);
    freopen("out","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
}

Compilation message

patkice.cpp: In function 'void solve()':
patkice.cpp:63:13: warning: 'sj' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |     resr=dfs(si,sj+1);
      |          ~~~^~~~~~~~~
patkice.cpp:63:13: warning: 'si' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 344 KB Output is correct
6 Correct 1 ms 412 KB Output is correct
7 Correct 0 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 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 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 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 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 1 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 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 1 ms 348 KB Output is correct