結果

問題 No.658 テトラナッチ数列 Hard
ユーザー bal4ubal4u
提出日時 2019-04-22 15:51:47
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 29,100 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-01 08:23:08
合計ジャッジ時間 1,622 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:9:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:17:34: 備考: in expansion of macro ‘gc’
   17 |         long long n = 0; int c = gc();
      |                                  ^~
main.c: 関数 ‘outs’ 内:
main.c:10:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   10 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:26:9: 備考: 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, s, Q;
	s = 2; for (i = 5; i < 5000; i++) {
		a[i] = s, s = (s + MOD + a[i] - a[i-4]) % MOD;
	}
	Q = (int)in(); while (Q--) outs(a[(int)((in()-1) % PERIOD)]);
	return 0;
}
0