Submission #447580

#TimeUsernameProblemLanguageResultExecution timeMemory
447580PiejanVDCPatkice (COCI20_patkice)C++17
0 / 50
1098 ms204 KiB
#include <bits/stdc++.h> using namespace std; int n,m; vector<string>v; bool 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; } signed main() { cin>>n>>m; v.resize(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; } } 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++; } 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++; } 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++; } 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++; } 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...