結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー bal4ubal4u
提出日時 2019-07-14 19:52:33
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 2,179 bytes
コンパイル時間 980 ms
コンパイル使用メモリ 30,312 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-16 04:46:54
合計ジャッジ時間 2,565 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// yukicoder: No.496 ワープクリスタル (給料日前編)
// 2019.7.14 bal4u

#include <stdio.h>
#include <string.h>

typedef long long ll;

#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 MAX 1000000
typedef struct { int t, x, y; ll b; } QUE;
QUE que[MAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i) {
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i]; que[i] = que[min]; que[min] = qt;
		min_heapify(min);
	}
}

void deq() {
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int t, int x, int y, ll b) {
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].t = t, que[i].x = x, que[i].y = y, que[i].b = b;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i]; que[i] = que[min]; que[min] = qt;
		i = min;
	}
}

//// 本問題関連
#define INF 0x33
typedef struct { int x, y, c; } T;
T t[55]; int N;
int vis[102][102];
int F;
int mv[2][2] = {{0,1},{1,0}};

int dijkstra(int gx, int gy) {
	int i, x, y, xx, yy, c = 0;
	ll b;

	memset(vis, INF, sizeof(vis));
	enq(0, 0, 0, 0);
	while (qsize) {
		c = que[0].t, x = que[0].x, y = que[0].y, b = que[0].b, deq();
		if (x == gx && y == gy) break;
		if (vis[x][y] <= c) continue;
		vis[x][y] = c;
		for (i = 0; i < 2; i++) {
			xx = x + mv[i][0], yy = y + mv[i][1];
			if (xx > gx || yy > gy) continue;
			if (vis[xx][yy] > c+F) enq(c+F, xx, yy, b);
		}
		for (i = 0; i < N; i++) {
			if ((b >> i) & 1) continue;
			xx = x + t[i].x, yy = y + t[i].y;
			if (xx > gx || yy > gy) continue;
			if (vis[xx][yy] > c+t[i].c) enq(c+t[i].c, xx, yy, b | (1LL << i));
		}
	}
	return c;
}

int main()
{
	int i, gx, gy;

	gx = in(), gy = in(), N = in(), F = in();
	for (i = 0; i < N; i++) t[i].x = in(), t[i].y = in(), t[i].c = in();
	printf("%d\n", dijkstra(gx, gy));
	return 0;
}
0