답안 #870564

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870564 2023-11-08T10:07:52 Z epicci23 Patkice (COCI20_patkice) C++17
0 / 50
1000 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){
  assert(min(i,j)>0);
  assert(i<=n);
  assert(j<=m);
  if(ar[i][j]=='.') 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 348 KB Output is correct
2 Execution timed out 1082 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
6 Execution timed out 1091 ms 348 KB Time limit exceeded
7 Halted 0 ms 0 KB -