답안 #377623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377623 2021-03-14T13:14:12 Z Nordway Patkice (COCI20_patkice) C++17
50 / 50
1 ms 748 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

const int N=5e3+11;
const int M=1e6+1;
const ll inf=1e9+11;
const ld EPS=1e-6;
const ll INF=1e18;
const ll mod=/*999999001*/1e9+7;
const int dx[4]={1,0,0,-1};
const int dy[4]={0,1,-1,0};

int a[N][N];
int x,y;

int dfs(int i,int j){
  if(x==i&&y==j){
    return 0;
  }
  if(a[i][j]<0||a[i][j]>3)return inf;
  return dfs(i+dx[a[i][j]],j+dy[a[i][j]])+1;
}

void solve(){
  int n,m;
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      char c;
      cin>>c;
      if(c=='x')x=i,y=j;
      if(c=='<')a[i][j]=2;
      else if(c=='>')a[i][j]=1;
      else if(c=='v')a[i][j]=0;
      else if(c=='^')a[i][j]=3;
      else if(c=='o')a[i][j]=4;
      else a[i][j]=-1;
    }
  }
  int mn=inf;
  char ans=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(a[i][j]==4){
        if(j<m){
          if(dfs(i,j+1)<mn){
            mn=dfs(i,j+1);
            ans='E';
          }
        }
        if(i>1){
          if(dfs(i-1,j)<mn){
            mn=dfs(i-1,j);
            ans='N';
          }
        }
        if(i<n){
          if(dfs(i+1,j)<mn){
            mn=dfs(i+1,j);
            ans='S';
          }
        }
        if(j>1){
          if(dfs(i,j-1)<mn){
            mn=dfs(i,j-1);
            ans='W';
          }
        }
        if(mn==inf)cout<<":(";
        else cout<<":)\n"<<ans;
        return ;
      }
    }
  }
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);
  int T=1;
  //cin>>T;
  for(int i=1;i<=T;i++){
    solve();
    cout<<nl;
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 748 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 748 KB Output is correct
11 Correct 1 ms 620 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 620 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct