結果

問題 No.979 Longest Divisor Sequence
ユーザー bal4ubal4u
提出日時 2020-02-26 17:39:06
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 378 ms / 2,000 ms
コード長 783 bytes
コンパイル時間 981 ms
コンパイル使用メモリ 29,528 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-03 18:21:31
合計ジャッジ時間 2,261 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 0 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 0 ms
4,376 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 378 ms
4,376 KB
testcase_15 AC 126 ms
4,380 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;

static inline void hmax(int *a, int b, int c) {
	if (*a < b) *a = b;
	if (*a < c) *a = c;
}

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

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