結果

問題 No.197 手品
ユーザー ぴろずぴろず
提出日時 2015-04-28 23:48:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 121 ms / 1,000 ms
コード長 1,387 bytes
コンパイル時間 4,516 ms
コンパイル使用メモリ 73,588 KB
実行使用メモリ 56,752 KB
最終ジャッジ日時 2023-09-27 09:24:56
合計ジャッジ時間 9,879 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
55,492 KB
testcase_01 AC 111 ms
56,372 KB
testcase_02 AC 111 ms
56,184 KB
testcase_03 AC 113 ms
55,824 KB
testcase_04 AC 108 ms
56,136 KB
testcase_05 AC 110 ms
56,204 KB
testcase_06 AC 111 ms
56,152 KB
testcase_07 AC 110 ms
55,996 KB
testcase_08 AC 106 ms
55,904 KB
testcase_09 AC 107 ms
55,928 KB
testcase_10 AC 107 ms
55,844 KB
testcase_11 AC 112 ms
55,996 KB
testcase_12 AC 109 ms
56,120 KB
testcase_13 AC 114 ms
55,908 KB
testcase_14 AC 115 ms
56,564 KB
testcase_15 AC 121 ms
55,608 KB
testcase_16 AC 116 ms
56,028 KB
testcase_17 AC 113 ms
55,808 KB
testcase_18 AC 113 ms
55,988 KB
testcase_19 AC 108 ms
55,928 KB
testcase_20 AC 114 ms
54,212 KB
testcase_21 AC 112 ms
55,764 KB
testcase_22 AC 112 ms
55,552 KB
testcase_23 AC 106 ms
56,064 KB
testcase_24 AC 110 ms
55,776 KB
testcase_25 AC 110 ms
56,752 KB
testcase_26 AC 111 ms
56,124 KB
testcase_27 AC 110 ms
55,728 KB
testcase_28 AC 110 ms
56,124 KB
testcase_29 AC 113 ms
55,816 KB
testcase_30 AC 111 ms
55,812 KB
testcase_31 AC 109 ms
56,288 KB
testcase_32 AC 110 ms
55,996 KB
testcase_33 AC 112 ms
56,116 KB
testcase_34 AC 113 ms
56,220 KB
testcase_35 AC 109 ms
55,608 KB
testcase_36 AC 110 ms
55,888 KB
testcase_37 AC 114 ms
56,056 KB
testcase_38 AC 112 ms
55,936 KB
testcase_39 AC 106 ms
56,068 KB
testcase_40 AC 111 ms
56,212 KB
testcase_41 AC 114 ms
56,120 KB
testcase_42 AC 110 ms
55,816 KB
testcase_43 AC 117 ms
56,424 KB
testcase_44 AC 118 ms
55,816 KB
testcase_45 AC 113 ms
55,620 KB
testcase_46 AC 113 ms
56,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no197;

import java.util.Scanner;

public class Main {
	/*
	 * 123
	 * 132
	 * 213
	 * 231
	 * 312
	 * 321
	 */
	static int[][] perm = {{1,2,3},{1,3,2},{2,1,3},{2,3,1},{3,1,2},{3,2,1}};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] bef = sc.next().toCharArray();
		long n = sc.nextLong();
		char[] aft = sc.next().toCharArray();

		int[][] a = {{0,1,1,0,0,0},{1,0,0,0,1,0},{1,0,0,1,0,0},{0,0,1,0,0,1},{0,1,0,0,0,1},{0,0,0,1,1,0}};
        int[][] x = new int[6][6];
        for(int i=0;i<6;i++) {
            x[i][i] = 1;
        }
        while(n > 0) {
            if (n % 2 == 1) {
                x = mul(x,a);
            }
            a = mul(a,a);
            n /= 2;
        }

        LOOP: for(int i=0;i<6;i++) {
        	if (x[0][i] == 1) {
        		for(int j=0;j<3;j++) {
        			if (bef[j] != aft[perm[i][j]-1]) {
        				continue LOOP;
        			}
        		}
        		System.out.println("FAILURE");
        		return;
        	}
        }
        System.out.println("SUCCESS");
	}
    static int[][] mul(int[][] a,int[][] b) {
        int n = a.length;
        int[][] c = new int[n][n];
        for(int i=0;i<n;i++) {
            for(int j=0;j<n;j++) {
                for(int k=0;k<n;k++) {
                    c[i][j] |= a[i][k] & b[k][j];
                }
            }
        }
        return c;
    }
}
0