답안 #436078

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
436078 2021-06-24T08:03:40 Z peace Patkice (COCI20_patkice) C++17
50 / 50
1 ms 332 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 105;
const int SZ = N * N;

const int hi[] = {0, -1, 1, 0};
const int hj[] = {1, 0, 0, -1};
const char *cv = "ENSW";

char s[N];
int c[N][N];

int main() {
	map<char,int> mp;
	mp['>'] = 0;
	mp['^'] = 1;
	mp['v'] = 2;
	mp['<'] = 3;
	mp['o'] = -1;
	mp['x'] = -2;
	mp['.'] = -3;

	int n, m;
	scanf("%d%d", &n, &m);
	int src_i, src_j;
	for (int i = 0; i < n; i++) {
		scanf("%s", s);
		for (int j = 0; j < m; j++) {
			c[i][j] = mp[s[j]];
			if (c[i][j] == -1) {
				src_i = i;
				src_j = j;
			}
		}
	}
	int res = -1;
	char res_c;
	for (int dr = 0; dr < 4; dr++) {
		int i = src_i;
		int j = src_j;
		int sz = 0;
		i += hi[dr];
		j += hj[dr];
		sz++;
		while (c[i][j] >= 0) {
			int val = c[i][j];
			i += hi[val];
			j += hj[val];
			sz++;
		}
		if (c[i][j] != -2) continue;
		if (res < 0 || res > sz) {
			res = sz;
			res_c = cv[dr];
		}
	}
	if (res < 0) puts(":(");
	else {
		puts(":)");
		printf("%c\n", res_c);
	}
}

Compilation message

patkice.cpp: In function 'int main()':
patkice.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
patkice.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |   scanf("%s", s);
      |   ~~~~~^~~~~~~~~
patkice.cpp:45:5: warning: 'src_j' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |   j += hj[dr];
      |   ~~^~~~~~~~~
patkice.cpp:44:5: warning: 'src_i' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |   i += hi[dr];
      |   ~~^~~~~~~~~
# 결과 실행 시간 메모리 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 276 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 204 KB Output is correct
10 Correct 1 ms 204 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 288 KB Output is correct
4 Correct 1 ms 204 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 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 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 292 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 204 KB Output is correct
17 Correct 1 ms 296 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