Submission #72593680


Source Code Expand

Copy
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int n, m;
int x[128], y[128];
int douro[128][128];
int mincost[128][128];
struct status_s {
int cur, from, cost;
};
int qs;
struct status_s q[128 * 128 * 128];
void qadjust(int pos) {
for (;;) {
int i, mc = pos;
for (i = 1; i <= 2; i++) {
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int n, m;
int x[128], y[128];
int douro[128][128];

int mincost[128][128];

struct status_s {
	int cur, from, cost;
};

int qs;
struct status_s q[128 * 128 * 128];

void qadjust(int pos) {
	for (;;) {
		int i, mc = pos;
		for (i = 1; i <= 2; i++) {
			int c = pos * 2 + i;
			if (c < qs && q[c].cost < q[mc].cost) mc = c;
		}
		if (mc == pos) {
			if (pos == 0) return;
			pos = (pos - 1) / 2;
		} else {
			struct status_s temp = q[pos];
			q[pos] = q[mc];
			q[mc] = temp;
			pos = mc;
		}
	}
}

void qadd(struct status_s s) {
	if (qs + 1 >= (int)(sizeof(q) / sizeof(*q))) {
		puts("OVERFLOW!!!!!");
		exit(42);
	}
	q[qs++] = s;
	qadjust(qs - 1);
}

struct status_s qget(void) {
	struct status_s res = q[0];
	if (qs <= 0) {
		puts("UNDERFLOW!!!!!");
		exit(72);
	}
	if (--qs > 0) {
		q[0] = q[qs];
		qadjust(0);
	}
	return res;
}

int main(void) {
	int i;
	int ans = -1;
	if (scanf("%d%d", &n, &m) != 2) return 1;
	for (i = 1; i <= n; i++) {
		if (scanf("%d%d", &x[i], &y[i]) != 2) return 1;
	}
	memset(douro, -1, sizeof(douro));
	for (i = 0; i < m; i++) {
		int a, b, c;
		if (scanf("%d%d%d", &a, &b, &c) != 3) return 1;
		if (douro[a][b] < 0 || c < douro[a][b]) douro[a][b] = douro[b][a] = c;
	}
	memset(mincost, -1, sizeof(mincost));
	mincost[1][1] = 0;
	qadd((struct status_s){ 1, 1, 0 });
	while (qs > 0) {
		struct status_s cur = qget();
		if (mincost[cur.cur][cur.from] == cur.cost) {
			for (i = 1; i <= n; i++) {
				if (douro[cur.cur][i] >= 0) {
					/* 今の料金所から来た方向と行く方向の内積を取り、それが0以下ならおk */
					int cx = x[cur.cur], cy = y[cur.cur];
					int px = x[cur.from], py = y[cur.from];
					int nx = x[i], ny = y[i];
					int dx1 = px - cx, dy1 = py - cy;
					int dx2 = nx - cx, dy2 = ny - cy;
					if (dx1 * dx2 + dy1 * dy2 <= 0) {
						int nc = cur.cost + douro[cur.cur][i];
						if (mincost[i][cur.cur] < 0 || nc < mincost[i][cur.cur]) {
							mincost[i][cur.cur] = nc;
							qadd((struct status_s){ i, cur.cur, nc });
						}
					}
				}
			}
		}
	}
	for (i = 1; i <= n; i++) {
		int c = mincost[2][i];
		if (c >= 0 && (ans < 0 || c < ans)) ans = c;
	}
	printf("%d\n", ans);
	return 0;
}

Submission Info

Submission Time
Task route - 象使い (Route)
User mikecat
Language C23 (GCC 14.2.0)
Score 100
Code Size 2330 Byte
Status AC
Exec Time 5 ms
Memory 1988 KiB

Judge Result

Set Name Set01 Set02 Set03 Set04 Set05 Set06 Set07 Set08 Set09 Set10
Score / Max Score 10 / 10 10 / 10 10 / 10 10 / 10 10 / 10 10 / 10 10 / 10 10 / 10 10 / 10 10 / 10
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
Set01 01
Set02 02
Set03 03
Set04 04
Set05 05
Set06 06
Set07 07
Set08 08
Set09 09
Set10 10
Case Name Status Exec Time Memory
01 AC 1 ms 1780 KiB
02 AC 0 ms 1872 KiB
03 AC 0 ms 1728 KiB
04 AC 1 ms 1776 KiB
05 AC 1 ms 1700 KiB
06 AC 1 ms 1752 KiB
07 AC 1 ms 1728 KiB
08 AC 1 ms 1784 KiB
09 AC 4 ms 1908 KiB
10 AC 5 ms 1988 KiB


2026-01-19 (Mon)
19:19:29 +09:00