結果

問題 No.658 テトラナッチ数列 Hard
ユーザー tentententen
提出日時 2020-09-04 16:42:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 772 bytes
コンパイル時間 2,126 ms
コンパイル使用メモリ 75,064 KB
実行使用メモリ 58,620 KB
最終ジャッジ日時 2024-05-04 14:37:45
合計ジャッジ時間 5,477 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
54,064 KB
testcase_01 AC 120 ms
53,972 KB
testcase_02 AC 102 ms
52,960 KB
testcase_03 AC 120 ms
54,096 KB
testcase_04 AC 244 ms
58,396 KB
testcase_05 AC 253 ms
58,460 KB
testcase_06 AC 252 ms
57,840 KB
testcase_07 AC 256 ms
58,068 KB
testcase_08 AC 255 ms
58,432 KB
testcase_09 AC 283 ms
58,112 KB
testcase_10 AC 259 ms
58,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int MAX = 5000;
    static int MOD = 4912;
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int[] arr = new int[MAX];
    	arr[3] = 1;
    	HashMap<Integer, Integer> map = new HashMap<>();
    	for (int i = 4; i < MAX; i++) {
    	    arr[i] = (arr[i - 1] + arr[i - 2] + arr[i - 3] + arr[i - 4]) % 17;
    	}
    	int n = sc.nextInt();
    	StringBuilder sb = new StringBuilder();
    	for (int i = 0; i < n; i++) {
    	    long x = sc.nextLong() - 1;
    	    int idx;
    	    if (x >= 4) {
    	        idx = (int)((x - 4) % MOD + 4);
    	    } else {
    	        idx = (int)x;
    	    }
    	    sb.append(arr[idx]).append("\n");
    	}
    	System.out.print(sb);
    }
}
0