結果
問題 | No.658 テトラナッチ数列 Hard |
ユーザー | Grenache |
提出日時 | 2018-03-04 00:56:16 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 963 ms / 2,000 ms |
コード長 | 1,654 bytes |
コンパイル時間 | 5,225 ms |
コンパイル使用メモリ | 74,352 KB |
実行使用メモリ | 68,708 KB |
最終ジャッジ日時 | 2023-09-18 15:39:11 |
合計ジャッジ時間 | 11,039 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 129 ms
55,812 KB |
testcase_01 | AC | 129 ms
55,772 KB |
testcase_02 | AC | 132 ms
55,744 KB |
testcase_03 | AC | 163 ms
56,588 KB |
testcase_04 | AC | 520 ms
61,416 KB |
testcase_05 | AC | 547 ms
64,888 KB |
testcase_06 | AC | 635 ms
66,884 KB |
testcase_07 | AC | 662 ms
66,904 KB |
testcase_08 | AC | 716 ms
68,388 KB |
testcase_09 | AC | 963 ms
68,708 KB |
testcase_10 | AC | 952 ms
68,404 KB |
ソースコード
import java.io.*; import java.util.*; public class Main_yukicoder658 { private static Scanner sc; private static Printer pr; private static void solve() { int q = sc.nextInt(); int[] aa = {0, 0, 0, 1}; int[][] xx = {{0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}, {1, 1, 1, 1}}; long[] n = new long[q]; for (int i = 0; i < q; i++) { n[i] = sc.nextLong(); if (n[i] < 4) { pr.println(0); } else { int[] a = aa; int[][] x = xx; long loop = n[i] - 4; while (loop > 0) { if (loop % 2 == 1) { a = Matrix.mul(x, a); } x = Matrix.mul(x, x); loop /= 2; } pr.println(a[3]); } } } private static final int MOD = 17; private static class Matrix { static int[] mul(int[][] x, int[] a) { int n = a.length; int[] b = new int[n]; for (int i = 0; i < n; i++) { long tmp = 0; for (int j = 0; j < n; j++) { tmp += (long)x[i][j] * a[j]; tmp %= MOD; } b[i] = (int)tmp; } return b; } static int[][] mul(int[][] x, int[][] x2) { int n = x[0].length; int[][] b = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { long tmp = 0; for (int k = 0; k < n; k++) { tmp += (long)x[i][k] * x2[k][j]; tmp %= MOD; } b[i][j] = (int)tmp; } } return b; } } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }