結果

問題 No.1105 Many Triplets
ユーザー tentententen
提出日時 2021-05-11 10:28:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 2,873 bytes
コンパイル時間 4,845 ms
コンパイル使用メモリ 78,304 KB
実行使用メモリ 56,576 KB
最終ジャッジ日時 2023-10-21 14:34:28
合計ジャッジ時間 6,109 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
56,052 KB
testcase_01 AC 97 ms
55,532 KB
testcase_02 AC 97 ms
56,096 KB
testcase_03 AC 96 ms
56,204 KB
testcase_04 AC 97 ms
55,860 KB
testcase_05 AC 97 ms
56,060 KB
testcase_06 AC 99 ms
56,064 KB
testcase_07 AC 96 ms
56,160 KB
testcase_08 AC 96 ms
56,068 KB
testcase_09 AC 97 ms
56,128 KB
testcase_10 AC 96 ms
56,092 KB
testcase_11 AC 94 ms
56,032 KB
testcase_12 AC 95 ms
56,492 KB
testcase_13 AC 100 ms
56,344 KB
testcase_14 AC 100 ms
55,556 KB
testcase_15 AC 105 ms
56,060 KB
testcase_16 AC 92 ms
56,576 KB
testcase_17 AC 95 ms
56,500 KB
testcase_18 AC 93 ms
54,708 KB
testcase_19 AC 93 ms
56,188 KB
testcase_20 AC 95 ms
56,176 KB
testcase_21 AC 105 ms
56,068 KB
testcase_22 AC 104 ms
55,864 KB
testcase_23 AC 95 ms
56,316 KB
testcase_24 AC 95 ms
56,056 KB
testcase_25 AC 98 ms
56,056 KB
testcase_26 AC 89 ms
56,044 KB
testcase_27 AC 97 ms
56,084 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[] 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();
    }
}
0