結果

問題 No.1105 Many Triplets
ユーザー tentententen
提出日時 2022-08-30 16:28:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 2,110 bytes
コンパイル時間 2,466 ms
コンパイル使用メモリ 79,324 KB
実行使用メモリ 40,408 KB
最終ジャッジ日時 2024-04-25 01:25:46
合計ジャッジ時間 5,774 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
38,260 KB
testcase_01 AC 76 ms
38,404 KB
testcase_02 AC 72 ms
38,224 KB
testcase_03 AC 76 ms
38,668 KB
testcase_04 AC 88 ms
40,032 KB
testcase_05 AC 76 ms
39,904 KB
testcase_06 AC 75 ms
38,684 KB
testcase_07 AC 75 ms
40,080 KB
testcase_08 AC 89 ms
39,992 KB
testcase_09 AC 89 ms
39,984 KB
testcase_10 AC 88 ms
40,160 KB
testcase_11 AC 90 ms
40,052 KB
testcase_12 AC 78 ms
39,948 KB
testcase_13 AC 78 ms
38,476 KB
testcase_14 AC 84 ms
38,956 KB
testcase_15 AC 73 ms
38,184 KB
testcase_16 AC 92 ms
40,040 KB
testcase_17 AC 77 ms
39,692 KB
testcase_18 AC 74 ms
38,256 KB
testcase_19 AC 79 ms
40,408 KB
testcase_20 AC 89 ms
39,676 KB
testcase_21 AC 85 ms
40,216 KB
testcase_22 AC 80 ms
40,032 KB
testcase_23 AC 85 ms
39,856 KB
testcase_24 AC 75 ms
38,800 KB
testcase_25 AC 86 ms
40,156 KB
testcase_26 AC 89 ms
39,796 KB
testcase_27 AC 86 ms
39,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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[][][] matrix = new long[60][3][3];
        matrix[0] = new long[][]{{1, MOD - 1, 0}, {0, 1, MOD - 1}, {MOD - 1, 0, 1}};
        for (int i = 1; i < 60; i++) {
            for (int a = 0; a < 3; a++) {
                for (int b = 0; b < 3; b++) {
                    for (int c = 0; c < 3; c++) {
                        matrix[i][a][c] += matrix[i - 1][a][b] * matrix[i - 1][b][c];
                        matrix[i][a][c] %= MOD;
                    }
                }
            }
        }
        long[] ans = new long[3];
        for (int i = 0; i < 3; i++) {
            ans[i] = sc.nextInt();
        }
        for (int i = 59; i >= 0; i--) {
            if (n < (1L << i)) {
                continue;
            }
            n -= (1L << i);
            long[] nexts = new long[6];
            for (int a = 0; a < 3; a++) {
                for (int b = 0; b < 3; b++) {
                    nexts[a] += matrix[i][a][b] * ans[b] % MOD;
                    nexts[a] %= MOD;
                }
            }
            ans = nexts;
        }
        System.out.println(ans[0] + " " + ans[1] + " " + ans[2]);
    }
    
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0