Submission #870566

#TimeUsernameProblemLanguageResultExecution timeMemory
870566epicci23Patkice (COCI20_patkice)C++17
50 / 50
1 ms600 KiB
#include "bits/stdc++.h" using namespace std; #define pb push_back #define endl "\n" #define int long long #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH * SIMPLIFY THE PROBLEM * READ THE STATEMENT CAREFULLY !!! if there is an specified/interesting smth(i.e. constraint) in the statement, then you must be careful about that */ vector<string> ar; int ok=0,d=0; int n,m; void dfs(int i,int j){ if(ar[i][j]=='.' || ar[i][j]=='o') return; if(ar[i][j]=='x'){ ok=1; return; } d++; if(ar[i][j]=='>') dfs(i,j+1); else if(ar[i][j]=='<') dfs(i,j-1); else if(ar[i][j]=='v') dfs(i+1,j); else dfs(i-1,j); } void solve(){ ar.pb(""); cin >> n >> m; int a = 0 , b = 0; for(int i=1;i<=n;i++){ string s; cin >> s; s = " " + s; ar.pb(s); for(int j=1;j<=m;j++){ if(ar[i][j]=='o'){ a = i; b = j; break; } } } vector<pair<int,char>> v; ok=d=0; dfs(a,b+1); if(ok) v.pb({d,'E'}); ok=d=0; dfs(a-1,b); if(ok) v.pb({d,'N'}); d=ok=0; dfs(a+1,b); if(ok) v.pb({d,'S'}); d=ok=0; dfs(a,b-1); if(ok) v.pb({d,'W'}); if(v.empty()){ cout << ":(\n"; return; } cout << ":)\n"; sort(all(v)); cout << v[0].second << endl; } int32_t main(){ cin.tie(0); ios::sync_with_stdio(0); int t=1;//cin >> t; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...