結果

問題 No.2441 行列累乗
ユーザー kusagame12kusagame12
提出日時 2023-11-07 18:55:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 1,137 bytes
コンパイル時間 2,841 ms
コンパイル使用メモリ 79,932 KB
実行使用メモリ 57,912 KB
最終ジャッジ日時 2023-11-07 18:55:14
合計ジャッジ時間 6,586 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
57,492 KB
testcase_01 AC 129 ms
56,336 KB
testcase_02 AC 140 ms
57,788 KB
testcase_03 AC 141 ms
57,672 KB
testcase_04 AC 130 ms
56,424 KB
testcase_05 AC 141 ms
57,560 KB
testcase_06 AC 129 ms
56,328 KB
testcase_07 AC 129 ms
56,360 KB
testcase_08 AC 129 ms
56,324 KB
testcase_09 AC 141 ms
56,332 KB
testcase_10 AC 130 ms
56,336 KB
testcase_11 AC 141 ms
57,644 KB
testcase_12 AC 143 ms
57,400 KB
testcase_13 AC 140 ms
57,604 KB
testcase_14 AC 142 ms
56,308 KB
testcase_15 AC 142 ms
55,332 KB
testcase_16 AC 144 ms
57,680 KB
testcase_17 AC 169 ms
57,912 KB
testcase_18 AC 143 ms
57,748 KB
testcase_19 AC 142 ms
57,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int[][] rs = new int[2][2];
        for (int i = 0 ; i < 2 ; i++){
            for (int j = 0 ; j < 2 ; j++){
                rs[i][j] = sc.nextInt();
            } 
        }
        
        int[][] ans = new int[2][2];
        for(int i = 0 ; i < 2 ; i++){
            if(i == 0){
                ans = calc(rs , rs);
            }else{
                ans = calc(ans , rs);
            }
        }
        
        for(int i = 0 ; i < 2 ; i++){
            for(int j = 0 ; j < 2 ; j++){
                System.out.print(ans[i][j]+" ");
            }
            System.out.println();
        }
    
    }
    
    private static int[][] calc(int[][] rs1 , int[][] rs2){
        int[][] ans = new int[2][2];
        for(int i = 0 ; i < 2 ; i++){
            for(int j = 0 ; j < 2 ; j++){
                for(int k = 0 ; k < 2 ; k++){
                    ans[i][j] += rs1[i][k] * rs2[k][j];
                }
            }
        }
        return ans;
    }
}
0