結果
| 問題 |
No.658 テトラナッチ数列 Hard
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-04-22 15:36:46 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 826 bytes |
| コンパイル時間 | 209 ms |
| コンパイル使用メモリ | 30,080 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-11 00:09:44 |
| 合計ジャッジ時間 | 1,093 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 |
コンパイルメッセージ
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]);
| ^~
ソースコード
// 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;
}
bal4u