結果

問題 No.1105 Many Triplets
ユーザー tentententen
提出日時 2021-11-24 11:22:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 2,163 bytes
コンパイル時間 2,384 ms
コンパイル使用メモリ 75,176 KB
実行使用メモリ 54,120 KB
最終ジャッジ日時 2023-09-08 18:07:35
合計ジャッジ時間 6,526 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
53,044 KB
testcase_01 AC 79 ms
52,504 KB
testcase_02 AC 81 ms
52,552 KB
testcase_03 AC 82 ms
53,124 KB
testcase_04 AC 83 ms
52,888 KB
testcase_05 AC 81 ms
52,616 KB
testcase_06 AC 89 ms
52,568 KB
testcase_07 AC 80 ms
52,680 KB
testcase_08 AC 80 ms
52,632 KB
testcase_09 AC 81 ms
52,628 KB
testcase_10 AC 81 ms
52,768 KB
testcase_11 AC 83 ms
54,120 KB
testcase_12 AC 83 ms
52,628 KB
testcase_13 AC 85 ms
53,792 KB
testcase_14 AC 83 ms
53,060 KB
testcase_15 AC 83 ms
53,836 KB
testcase_16 AC 91 ms
53,804 KB
testcase_17 AC 83 ms
53,808 KB
testcase_18 AC 83 ms
53,508 KB
testcase_19 AC 81 ms
53,140 KB
testcase_20 AC 79 ms
52,528 KB
testcase_21 AC 81 ms
52,840 KB
testcase_22 AC 82 ms
53,672 KB
testcase_23 AC 83 ms
52,496 KB
testcase_24 AC 83 ms
52,804 KB
testcase_25 AC 82 ms
53,032 KB
testcase_26 AC 81 ms
52,496 KB
testcase_27 AC 86 ms
52,704 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[] ans = new long[3];
        for (int i = 0; i < 3; i++) {
            ans[i] = sc.nextInt();
        }
        long[][][] matrix = new long[63][3][3];
        matrix[0][0][0] = 1;
        matrix[0][0][1] = MOD - 1;
        matrix[0][1][1] = 1;
        matrix[0][1][2] = MOD - 1;
        matrix[0][2][2] = 1;
        matrix[0][2][0] = MOD - 1;
        for (int i = 1; i < 63; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    for (int l = 0; l < 3; l++) {
                        matrix[i][j][l] += matrix[i - 1][j][k] * matrix[i - 1][k][l] % MOD;
                        matrix[i][j][l] %= MOD;
                    }
                }
            }
        }
        for (int i = 62; i >= 0; i--) {
            if (n < (1L << i)) {
                continue;
            }
            long[] next = new long[3];
            n -= (1L << i);
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    next[j] += matrix[i][j][k] * ans[k] % MOD;
                    next[j] %= MOD;
                }
            }
            ans = next;
        }
        System.out.println(ans[0] + " " + ans[1] + " " + ans[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 double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0