답안 #870566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870566 2023-11-08T10:09:24 Z epicci23 Patkice (COCI20_patkice) C++17
50 / 50
1 ms 600 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct