結果

問題 No.34 砂漠の行商人
ユーザー bal4ubal4u
提出日時 2019-06-30 09:21:36
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,452 bytes
コンパイル時間 720 ms
コンパイル使用メモリ 30,188 KB
実行使用メモリ 52,968 KB
最終ジャッジ日時 2023-09-19 03:55:14
合計ジャッジ時間 2,272 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:8:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:14:24: 備考: in expansion of macro ‘gc’
   14 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.34 砂漠の行商人
// 2019.6.30 bal4u

#include <stdio.h>
#include <string.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;
}

#define INF 0x55
#define QMAX 5000000
typedef struct { int r, c, v, t; } Q;
Q q[QMAX+5]; int top, end; int qmax;
int N;
char map[103][103];
int mv[4][2] = {{0,-1},{-1,0},{0,1},{1,0}};
int vis[103][103];

int bfs(int V, int sr, int sc, int gr, int gc) {
	int i, r, c, v, t, rr, cc, vv;
	
	top = 0, end = 1;
	q[0].r = sr, q[0].c = sc, q[0].v = V, q[0].t = 0;
	while (top != end) {
		r = q[top].r, c = q[top].c, v = q[top].v, t = q[top].t, ++top;
		if (r == gr && c == gc) return t;
		if (vis[r][c] >= v) continue;
		vis[r][c] = v;
		for (i = 0; i < 4; i++) {
			rr = r + mv[i][0], cc = c + mv[i][1];
			if (rr < 0 || rr >= N || cc < 0 || cc >= N) continue;
			vv = v-map[rr][cc];
			if (vv <= 0) continue;
			if (vv > vis[rr][cc]) {
				q[end].r = rr, q[end].c = cc, q[end].v = vv, q[end].t = t+1, ++end;
				if (end > qmax) qmax = end;
			}
		}
	}
	return -1;
}
		
int main()
{
	int r, c, V, sr, sc, gr, gc;

	N = in(), V = in();
	sc = in()-1, sr = in()-1, gc = in()-1, gr = in()-1;
	for (r = 0; r < N; r++) for (c = 0; c < N; c++) {
		map[r][c] = gc() & 0xf, gc();
	}
	printf("%d\n", bfs(V, sr, sc, gr, gc));
	printf("qmax=%d\n", qmax);
	return 0;
}
0