Submission #870182

#TimeUsernameProblemLanguageResultExecution timeMemory
870182aegPatkice (COCI20_patkice)C++14
30 / 50
1 ms688 KiB
#include<bits/stdc++.h> using namespace std; vector<string> a; int r,s; int f(int x, int y) { if(a[y][x] == 'x') return 0; if(a[y][x] == '.' || a[y][x] == 'o') return INT_MIN; int chx=0, chy=0; if(a[y][x]=='<') chx--; else if(a[y][x]=='>') chx++; else if(a[y][x]=='^') chy--; else chy++; int ans = f(x+chx, y+chy); if(ans < 0) return INT_MIN; return ans+1; } int main () { cin>>r>>s; a.assign(r,""); for(int i=0; i<r; i++) cin>>a[i]; int x, y; for(int i=0; i<r; i++) for(int j=0; j<s; j++) { if(a[i][j]=='o') { y=i; x=j; } } int N = f(x,y-1), S = f(x,y+1), W = f(x-1,y), E = f(x+1, y); int maxi = max(max(S,N),max(W,E)); int mini = INT_MAX; if(S >= 0) mini = min(mini, S); if(N >= 0) mini = min(mini, N); if(W >= 0) mini = min(mini, W); if(E >= 0) mini = min(mini, E); if(maxi < 0) { cout << ":(\n"; return 0; } cout << ":)\n"; if(S == mini) cout<<"S\n"; else if(N == mini) cout<<"N\n"; else if(W == mini) cout<<"W\n"; else cout<<"E\n"; }

Compilation message (stderr)

patkice.cpp: In function 'int main()':
patkice.cpp:28:56: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   28 |     int N = f(x,y-1), S = f(x,y+1), W = f(x-1,y), E = f(x+1, y);
      |                                                       ~^~~~~~~~
patkice.cpp:28:56: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...