답안 #1016153

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

using namespace std;

const int N = 100 + 10;
char c;
int n, m, d[] = {-1, 1, 0, 0};
char M[N][N];
bool seen[N][N];

bool valid(int x, int y)
{
  return x >= 0 && y >= 0 && x < n && y < m;
}

void dfs(int x, int y)
{
  // cerr << x << ' ' << y << endl;
  seen[x][y] = true;
  if(M[x][y] == 'x')
    {
      cout << ":)\n";
      cout << c << endl;
      exit(0);
    }

  if(M[x][y] == '.')
    return;
  
  string s = "^v><";
  string D = "NSEW";
  for(int i = 0; i < 4; i ++)
    {
      int nx = x + d[i], ny = y + d[3 - i];
      if(M[x][y] == 'o')
	{
	  c = D[i];
	  if(valid(nx, ny) && !seen[nx][ny])
	    dfs(nx, ny);
	}
      else if(s[i] == M[x][y] && valid(nx, ny) && !seen[nx][ny])
	dfs(nx, ny);
    }
}

int main()
{
  cin >> n >> m;
  int oi, oj;
  for(int i = 0; i < n; i ++)
    for(int j = 0; j < m; j++)
      {
	cin >> M[i][j];
	if(M[i][j] == 'o') oi = i, oj = j;
      }
  dfs(oi, oj);
  cout << ":(\n";
  return 0;
}

Compilation message

patkice.cpp: In function 'int main()':
patkice.cpp:56:6: warning: 'oj' may be used uninitialized in this function [-Wmaybe-uninitialized]
   56 |   dfs(oi, oj);
      |   ~~~^~~~~~~~
patkice.cpp:56:6: warning: 'oi' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 444 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 432 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 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 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -