Submission #870183

# Submission time Handle Problem Language Result Execution time Memory
870183 2023-11-07T07:32:43 Z aeg Patkice (COCI20_patkice) C++14
50 / 50
1 ms 348 KB
#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(E == mini) cout<<"E\n";
    else if(N == mini) cout<<"N\n";
    else if(S == mini) cout<<"S\n";
    else cout<<"W\n";

}

Compilation message

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 time Memory 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 1 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 0 ms 348 KB Output is correct
# 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 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 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 0 ms 348 KB Output is correct
14 Correct 0 ms 344 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 1 ms 348 KB Output is correct