結果

問題 No.2999 Long Long Friedrice
コンテスト
ユーザー ygussany
提出日時 2024-12-24 00:04:16
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 798 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 320 ms
コンパイル使用メモリ 38,848 KB
最終ジャッジ日時 2026-02-22 12:38:16
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>

typedef struct Edge {
	struct Edge *next;
	int v;
} edge;

void chmax(int *a, int b)
{
	if (*a < b) *a = b;
}

int main()
{
	int i, N, A[2001], B[2001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	for (i = 1; i <= N; i++) scanf("%d", &(B[i]));
	
	int u, w;
	edge *adj[1000001] = {}, e[2001], *p;
	for (i = 1; i <= N; i++) {
		u = A[i];
		w = B[i];
		e[i].v = u + w;
		e[i].next = adj[u];
		adj[u] = &(e[i]);
	}
	
	int flag[1000001] = {}, q[2001], head, tail, ans = 0;
	flag[1] = 1;
	q[0] = 1;
	for (head = 0, tail = 1; head < tail; head++) {
		u = q[head];
		chmax(&ans, u);
		for (p = adj[u]; p != NULL; p = p->next) {
			w = p->v;
			if (flag[w] == 0) {
				flag[w] = 1;
				q[tail++] = w;
			}
		}
	}
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}
0