Submission #447578

# Submission time Handle Problem Language Result Execution time Memory
447578 2021-07-26T20:54:09 Z PiejanVDC Patkice (COCI20_patkice) C++17
0 / 50
1000 ms 204 KB
#include <bits/stdc++.h>
using namespace std;

signed main() {
    int n,m; cin>>n>>m;
    vector<string>v(n);
    for(auto &z : v) cin>>z;

    pair<int,int>s,e;
    for(int i = 0 ; i < n ; i++) {
        for(int j = 0 ; j < m ; j++) {
            if(v[i][j] == 'o') s.first=i,s.second=j;
            if(v[i][j] == 'x') e.first=i,e.second=j;
        }
    }

    auto valid = [&] (int x, int y) {
        if(x < 0 || x >= n || y < 0 || y >= m || v[x][y] == '.' || v[x][y] == 'x') return false;
        return true;
    };

    char winner;
    bool f = false;
    int cnt, best=INT_MAX;

    int x,y;
    char c;

    x = s.first, y = s.second+1;
    c = 'E';
    cnt=0;
    while(valid(x,y)) {
        if(v[x][y] == '<') y--;
        else if(v[x][y] == '^') x--;
        else if (v[x][y] == '>') y++;
        else x++;
        cnt++;
    }
    //cout << cnt << " ";
    if(x >= 0 && x < n && y >= 0 && y < m && v[x][y] == 'x') {
        if(cnt < best) best=cnt,winner=c,f=true;
    }
    cnt=0;
    x = s.first-1, y = s.second;
    c = 'N';
    while(valid(x,y)) {
        if(v[x][y] == '<') y--;
        else if(v[x][y] == '^') x--;
        else if (v[x][y] == '>') y++;
        else x++;
        cnt++;
    }
    //cout << cnt << " ";
    if(x >= 0 && x < n && y >= 0 && y < m && v[x][y] == 'x') {
        if(cnt < best) best=cnt,winner=c,f=true;
    }

    x = s.first+1, y = s.second;
    c = 'S';
    cnt=0;
    while(valid(x,y)) {
        if(v[x][y] == '<') y--;
        else if(v[x][y] == '^') x--;
        else if (v[x][y] == '>') y++;
        else x++;
        cnt++;
    }
    //cout << cnt << " ";
    if(x >= 0 && x < n && y >= 0 && y < m && v[x][y] == 'x') {
        if(cnt < best) best=cnt,winner=c,f=true;
    }

    x = s.first, y = s.second-1;
    c = 'W';
    cnt=0;
    while(valid(x,y)) {
        if(v[x][y] == '<') y--;
        else if(v[x][y] == '^') x--;
        else if (v[x][y] == '>') y++;
        else x++;
        cnt++;
    }
    //cout << cnt << " ";
    if(x >= 0 && x < n && y >= 0 && y < m && v[x][y] == 'x') {
        if(cnt < best) best=cnt,winner=c,f=true;
    }

    if(!f) cout << ":(";
    else cout << ":)\n" << winner;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -