結果
問題 | No.1105 Many Triplets |
ユーザー | tenten |
提出日時 | 2021-05-11 10:28:03 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 107 ms / 2,000 ms |
コード長 | 2,873 bytes |
コンパイル時間 | 2,530 ms |
コンパイル使用メモリ | 79,888 KB |
実行使用メモリ | 53,216 KB |
最終ジャッジ日時 | 2024-09-21 15:49:18 |
合計ジャッジ時間 | 6,185 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 92 ms
51,528 KB |
testcase_01 | AC | 87 ms
53,000 KB |
testcase_02 | AC | 107 ms
53,020 KB |
testcase_03 | AC | 104 ms
52,844 KB |
testcase_04 | AC | 92 ms
53,216 KB |
testcase_05 | AC | 103 ms
53,116 KB |
testcase_06 | AC | 103 ms
53,004 KB |
testcase_07 | AC | 91 ms
52,940 KB |
testcase_08 | AC | 97 ms
53,020 KB |
testcase_09 | AC | 104 ms
51,432 KB |
testcase_10 | AC | 104 ms
52,924 KB |
testcase_11 | AC | 98 ms
52,860 KB |
testcase_12 | AC | 95 ms
53,076 KB |
testcase_13 | AC | 103 ms
52,900 KB |
testcase_14 | AC | 95 ms
53,060 KB |
testcase_15 | AC | 102 ms
51,712 KB |
testcase_16 | AC | 93 ms
52,980 KB |
testcase_17 | AC | 95 ms
52,992 KB |
testcase_18 | AC | 105 ms
53,184 KB |
testcase_19 | AC | 104 ms
52,896 KB |
testcase_20 | AC | 94 ms
53,188 KB |
testcase_21 | AC | 104 ms
52,980 KB |
testcase_22 | AC | 106 ms
53,136 KB |
testcase_23 | AC | 91 ms
53,192 KB |
testcase_24 | AC | 92 ms
52,992 KB |
testcase_25 | AC | 96 ms
53,112 KB |
testcase_26 | AC | 97 ms
53,012 KB |
testcase_27 | AC | 94 ms
53,108 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { static final int MOD = 1000000007; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); long n = sc.nextLong() - 1; long[] org = new long[3]; for (int i = 0; i < 3; i++) { org[i] = sc.nextInt(); } long[][] base = new long[60][9]; base[0] = new long[]{1, MOD - 1, 0, 0, 1, MOD - 1, MOD - 1, 0, 1}; for (int i = 1; i < 60; i++) { base[i][0] = (base[i - 1][0] * base[i - 1][0] + base[i - 1][1] * base[i - 1][3] + base[i - 1][2] * base[i - 1][6]) % MOD; base[i][1] = (base[i - 1][0] * base[i - 1][1] + base[i - 1][1] * base[i - 1][4] + base[i - 1][2] * base[i - 1][7]) % MOD; base[i][2] = (base[i - 1][0] * base[i - 1][2] + base[i - 1][1] * base[i - 1][5] + base[i - 1][2] * base[i - 1][8]) % MOD; base[i][3] = (base[i - 1][3] * base[i - 1][0] + base[i - 1][4] * base[i - 1][3] + base[i - 1][5] * base[i - 1][6]) % MOD; base[i][4] = (base[i - 1][3] * base[i - 1][1] + base[i - 1][4] * base[i - 1][4] + base[i - 1][5] * base[i - 1][7]) % MOD; base[i][5] = (base[i - 1][3] * base[i - 1][2] + base[i - 1][4] * base[i - 1][5] + base[i - 1][5] * base[i - 1][8]) % MOD; base[i][6] = (base[i - 1][6] * base[i - 1][0] + base[i - 1][7] * base[i - 1][3] + base[i - 1][8] * base[i - 1][6]) % MOD; base[i][7] = (base[i - 1][6] * base[i - 1][1] + base[i - 1][7] * base[i - 1][4] + base[i - 1][8] * base[i - 1][7]) % MOD; base[i][8] = (base[i - 1][6] * base[i - 1][2] + base[i - 1][7] * base[i - 1][5] + base[i - 1][8] * base[i - 1][8]) % MOD; } for (int i = 59; i >= 0; i--) { if (n >= (1L << i)) { n -= (1L << i); long[] next = new long[3]; next[0] = (base[i][0] * org[0] + base[i][1] * org[1] + base[i][2] * org[2]) % MOD; next[1] = (base[i][3] * org[0] + base[i][4] * org[1] + base[i][5] * org[2]) % MOD; next[2] = (base[i][6] * org[0] + base[i][7] * org[1] + base[i][8] * org[2]) % MOD; org = next; } } System.out.println(org[0] + " " + org[1] + " " + org[2]); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }