답안 #1016490

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1016490 2024-07-08T06:54:57 Z vjudge1 Patkice (COCI20_patkice) C++17
30 / 50
1 ms 440 KB
#include<bits/stdc++.h>

using namespace std;

const int N = 100 + 10;
char M[N][N];
int cnt = 0, ans = 1e9;
bool found = false;
string out = ":(\n";
void dfs(int x, int y)
{
  cnt++;
  if(M[x][y] == 'x')
    {
      found = true;
      return;
    }

  if(M[x][y] == '^')
    dfs(x - 1, y);
  if(M[x][y] == 'v')
    dfs(x + 1, y);
  if(M[x][y] == '>')
    dfs(x, y + 1);
  if(M[x][y] == '<')
    dfs(x, y - 1);
}

int main()
{
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < n; i ++)
    for(int j = 0; j < m ; j ++)
      cin >> M[i][j];

  pair<int,int> O;
  for(int i = 0; i < n; i++)
    for(int j = 0; j < m; j ++)
      if(M[i][j] == 'o')
	O = {i, j};
  
  dfs(O.first, O.second + 1);
  if(found) {
    if(ans > cnt)
      out =  ":)\nE\n", ans = cnt;
  }
  cnt = 0, found = false;
  dfs(O.first - 1, O.second);
  if(found) {
   if(ans > cnt)
      out =  ":)\nN\n", ans = cnt;
  }
  cnt = 0, found = false;
  dfs(O.first, O.second - 1);
  if(found) {
   if(ans > cnt)
      out =  ":)\nW\n", ans = cnt;
  }

  cnt = 0, found = false;
  dfs(O.first + 1, O.second);
  if(found) {
   if(ans > cnt)
      out =  ":)\nS\n", ans = cnt;
  }
  
  cout << out;
  return 0;
}
// ENSW
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 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 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 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 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 440 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Incorrect 0 ms 348 KB Output isn't correct
18 Halted 0 ms 0 KB -