結果

問題 No.979 Longest Divisor Sequence
ユーザー bal4ubal4u
提出日時 2020-02-26 08:44:29
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 382 ms / 2,000 ms
コード長 831 bytes
コンパイル時間 415 ms
コンパイル使用メモリ 32,640 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 16:11:29
合計ジャッジ時間 1,543 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 0 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 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 6 ms
5,376 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 382 ms
5,376 KB
testcase_15 AC 123 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yuki 979 Longest Divisor Sequence
// 2020.2.26 bal4u

#include <stdio.h>
#include <math.h>

int getchar_unlocked(void);
#define gc() getchar_unlocked()

int in() {  // 整数の入力
	int n = 0; int c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int tbl[300005];
int ans = 1;

void count(int a, int b, int c) {
	if (tbl[a] <= tbl[b]) {
		tbl[a] = tbl[b]+1;
		if (tbl[a] > ans) ans = tbl[a];
	}
	if (c == b) return;
	if (tbl[a] <= tbl[c]) {
		tbl[a] = tbl[c]+1;
		if (tbl[a] > ans) ans = tbl[a];
	}
}
void calc(int a) {
	int i, b = sqrt(a);
	if (tbl[1]) count(a, 1, 1);
	for (i = 2; i <= b; ++i) {
		if (a % i == 0) count(a, i, a/i);
	}
}

int main()
{
	int i, N, A;

	N = in();
	while (N--) {
		A = in();
		if (tbl[A] == 0) tbl[A] = 1;
		if (A > 1) calc(A);
	}
	printf("%d\n", ans);
	return 0;
}
0