# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
870182 | aeg | Patkice (COCI20_patkice) | C++14 | 1 ms | 688 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |