Submission #495669

# Submission time Handle Problem Language Result Execution time Memory
495669 2021-12-19T20:40:17 Z asandikci Patkice (COCI20_patkice) C++17
50 / 50
1 ms 300 KB
#include"iostream"
// #include"vector"
// #include"queue"
// #include"deque"
// #include"set"
// #include"map"
// #include"algorithm"
// #include"iomanip"
// #include"cstring"
// #define int long long
using namespace std;

const int maxn=105;
const int INF = 1e9;

pair<int,int> duck;
char g[maxn][maxn];
int len=0;

void dfs(int x,int y){

  if(g[x][y]=='.' || g[x][y]=='o'){len=INF; return;}
  if(g[x][y]=='>'){ 
    len++;
    dfs(x,y+1);
  }
  if(g[x][y]=='<'){ 
    len++;
    dfs(x,y-1);
  }
  if(g[x][y]=='^'){ 
    len++;
    dfs(x-1,y);
  }
  if(g[x][y]=='v'){ 
    len++;
    dfs(x+1,y);
  }
  if(g[x][y]=='x') return;
}

void solve(){
  int n,m;
  cin >> n >> m;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin >> g[i][j];
      if(g[i][j]=='o'){
        duck = {i,j};
      }
    }
  }

  int a,b,c,d;
  // cout << duck.first << "*" << duck.second << "\n"; 
  dfs(duck.first,duck.second+1);
  a = len;
  len=0;
  dfs(duck.first,duck.second-1);
  b = len;
  len=0;
  dfs(duck.first+1,duck.second);
  c = len;
  len=0;
  dfs(duck.first-1,duck.second);
  d = len;

  // cout << a << "  " << b << "  " << c << "  " << d << "\n\n"; 
  int mini = min(a,min(b,min(c,d)));
  if(mini==INF){cout << ":(";}
  else{
    cout << ":)\n";
    if(a==mini){cout << "E";}
    else if(d==mini){cout << "N";} 
    else if(c==mini){cout << "S";}
    else if(b==mini){cout << "W";} 
  }
  




}

signed main(){
  // ios::sync_with_stdio(false); cin.tie(0);
  // freopen("","r",stdin);freopen("","w",stdout);
  int t=1;
  // cin >> t;
  for(int i=1;i<=t;i++){
    // cout << "Case " << i << ":\n";
    solve();
  }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 300 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 296 KB Output is correct