結果

問題 No.323 yuki国
ユーザー bal4ubal4u
提出日時 2019-07-07 17:51:35
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 83 ms / 5,000 ms
コード長 1,589 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 32,256 KB
実行使用メモリ 25,472 KB
最終ジャッジ日時 2024-04-15 08:41:22
合計ジャッジ時間 2,741 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 54 ms
6,656 KB
testcase_09 AC 47 ms
6,656 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 44 ms
25,472 KB
testcase_14 AC 52 ms
7,296 KB
testcase_15 AC 49 ms
6,784 KB
testcase_16 AC 52 ms
6,784 KB
testcase_17 AC 54 ms
14,080 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 45 ms
8,832 KB
testcase_20 AC 22 ms
10,624 KB
testcase_21 AC 76 ms
21,376 KB
testcase_22 AC 29 ms
10,880 KB
testcase_23 AC 72 ms
20,864 KB
testcase_24 AC 70 ms
6,656 KB
testcase_25 AC 68 ms
6,656 KB
testcase_26 AC 15 ms
6,528 KB
testcase_27 AC 14 ms
6,784 KB
testcase_28 AC 72 ms
6,784 KB
testcase_29 AC 83 ms
6,656 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:7:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    7 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:13:24: note: in expansion of macro 'gc'
   13 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: 323 yuki国
// 2019.7.7 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()    // 非負整数の入力
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void ins(char *s)  // 文字列の入力 スペース以下の文字で入力終了
{
	do *s = gc();
	while (*s++ > ' ');
	*(s-1) = 0;
}

#define QMAX 10000000
typedef struct { char r, c; int a; } Q;
Q q[QMAX+5]; int top;
int H, W, lim;
char map[53][53];
char vis[53][53][2002];
int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};

int bfs(int sr, int sc, int gr, int gc, int A, int B) {
	int i, r, c, a, t, rr, cc, f;
	
	f = 0, q[0].r = sr, q[0].c = sc, q[0].a = A, top = 1;
	while (top) {
		r = q[--top].r, c = q[top].c, a = q[top].a;
//		printf("r=%d, c=%d, a=%d\n", r, c, a);
		if (r == gr && c == gc && a == B) return 1;
		if (a >= lim || vis[r][c][a]) continue;
		vis[r][c][a] = 1;
		for (i = 0; i < 4; i++) {
			rr = r + mv[i][0], cc = c + mv[i][1];
			if (rr < 0 || rr >= H || cc < 0 || cc >= W) continue;
			if ((t = (map[rr][cc] == '.')) && a == 1) continue;
			if (map[r][c] == '*') { if (!t) f |= 1; }
			else if (t) f | 2;
			q[top].r = rr, q[top].c = cc, q[top++].a = a + 1 - (t<<1);
		}
		if (f == 3) return 1;
	}
	return 0;
}
	
int main()
{
	int i, r, c, sr, sc, gr, gc, A, B;
	
	H = in(), W = in();
	A = in(), sr = in(), sc = in();
	B = in(), gr = in(), gc = in();
	for (r = 0; r < H; r++) ins(map[r]);
	lim = A; if (lim < B) lim = B;
	lim += H + W;
	puts(bfs(sr, sc, gr, gc, A, B)? "Yes": "No");
	return 0;
}
0