답안 #398904

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
398904 2021-05-04T22:04:13 Z retsiger Patkice (COCI20_patkice) C++14
50 / 50
1 ms 332 KB
#include<bits/stdc++.h>
#define x first
#define y second
#define bug(x) cerr<<#x<<" = "<<x<<'\n'

using namespace std;

typedef pair <int, int> ii;

const int maxn = 105;

int N, M;
char A[maxn][maxn];

int dfs(int u, int v) {
  if (A[u][v] == 'o' || A[u][v] == '.') return -1;
  if (A[u][v] == 'x') return 1;
  int nu = u, nv = v;
  if (A[u][v] == '<') --nv;
  else if (A[u][v] == '>') ++nv;
  else if (A[u][v] == 'v') ++nu;
  else --nu;
  int k = dfs(nu, nv);
  if (k == -1) return -1;
  return 1 + k;
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
//  freopen("cc.inp", "r", stdin);
//  freopen("cc.out", "w", stdout);
  cin >> N >> M;
  int stx, sty;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      cin >> A[i][j];
      if (A[i][j] == 'o') {
        stx = i;
        sty = j;
      }
    }
  }
  int mn = (int)1e9;
  char ans = 'Z';
  int k = dfs(stx - 1, sty);
  if (k != -1) {
    if (k < mn) {
      mn = k;
      ans = 'N';
    }
  }
  k = dfs(stx + 1, sty);
  if (k != -1) {
    if (k < mn) {
      mn = k;
      ans = 'S';
    } else if (k == mn) {
      ans = min(ans, 'S');
    }
  }
  k = dfs(stx, sty - 1);
  if (k != -1) {
    if (k < mn) {
      mn = k;
      ans ='W';
    } else if (k == mn) {
      ans = min(ans, 'W');
    }
  }
  k = dfs(stx, sty + 1);
  if (k != -1) {
    if (k < mn) {
      mn = k;
      ans ='E';
    } else if (k == mn) {
      ans = min(ans, 'E');
    }
  }
  if (ans == 'Z') {
    cout << ":(";
  } else
    cout << ":)\n" << ans << '\n';
  return 0;
}

Compilation message

patkice.cpp: In function 'int main()':
patkice.cpp:52:10: warning: 'sty' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |   k = dfs(stx + 1, sty);
      |       ~~~^~~~~~~~~~~~~~
patkice.cpp:52:10: warning: 'stx' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct