結果

問題 No.658 テトラナッチ数列 Hard
ユーザー bal4ubal4u
提出日時 2019-04-22 15:36:46
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 826 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 31,104 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 07:30:18
合計ジャッジ時間 1,134 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:9:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:17:34: note: in expansion of macro 'gc'
   17 |         long long n = 0; int c = gc();
      |                                  ^~
main.c: In function 'outs':
main.c:10:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
   10 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:26:9: note: in expansion of macro 'pc'
   26 |         pc(ans[n][0]);
      |         ^~

ソースコード

diff #

// yukicoder: No.658 テトラナッチ数列 Hard
// 2019.4.22 bal4u
// 周期性に注目。周期 4912

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

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
long long in()
{
	long long n = 0; int c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

char ans[17][3] = {"0","1","2","3","4","5","6","7","8","9","10",
"11","12","13","14","15","16"};

void outs(int n) {
	pc(ans[n][0]);
	if (n >= 10) pc(ans[n][1]);
	pc('\n');
}

#define MOD 17
#define PERIOD 4912
int a[5000] = {0,0,0,1,1,2,4,8,15,29};

int main()
{
	int i, Q;
	for (i = 5; i < 5000; i++) {
		a[i] = (a[i-4]+a[i-3]+a[i-2]+a[i-1]) % MOD;
	}
	Q = (int)in(); while (Q--) outs(a[(int)((in()-1) % PERIOD)]);
	return 0;
}
0