結果

問題 No.197 手品
ユーザー mobius_bkstmobius_bkst
提出日時 2015-04-29 00:19:37
言語 Java21
(openjdk 21)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,453 bytes
コンパイル時間 3,921 ms
コンパイル使用メモリ 74,812 KB
実行使用メモリ 49,932 KB
最終ジャッジ日時 2023-09-09 15:25:25
合計ジャッジ時間 7,813 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,100 KB
testcase_01 AC 41 ms
49,708 KB
testcase_02 AC 42 ms
49,228 KB
testcase_03 AC 42 ms
49,400 KB
testcase_04 AC 42 ms
49,156 KB
testcase_05 AC 42 ms
49,328 KB
testcase_06 AC 42 ms
49,252 KB
testcase_07 AC 42 ms
49,340 KB
testcase_08 AC 42 ms
49,280 KB
testcase_09 AC 42 ms
49,092 KB
testcase_10 AC 41 ms
49,084 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 42 ms
49,404 KB
testcase_19 AC 42 ms
49,184 KB
testcase_20 AC 42 ms
49,232 KB
testcase_21 AC 43 ms
49,504 KB
testcase_22 WA -
testcase_23 AC 42 ms
49,244 KB
testcase_24 AC 42 ms
49,384 KB
testcase_25 AC 41 ms
49,204 KB
testcase_26 AC 41 ms
49,096 KB
testcase_27 AC 41 ms
49,116 KB
testcase_28 AC 42 ms
49,184 KB
testcase_29 AC 43 ms
49,932 KB
testcase_30 AC 43 ms
49,116 KB
testcase_31 AC 42 ms
49,168 KB
testcase_32 AC 42 ms
49,492 KB
testcase_33 AC 42 ms
47,140 KB
testcase_34 AC 41 ms
49,264 KB
testcase_35 AC 42 ms
49,192 KB
testcase_36 AC 42 ms
49,228 KB
testcase_37 AC 42 ms
49,292 KB
testcase_38 AC 42 ms
49,116 KB
testcase_39 AC 42 ms
49,100 KB
testcase_40 AC 42 ms
49,108 KB
testcase_41 AC 42 ms
49,232 KB
testcase_42 AC 42 ms
49,024 KB
testcase_43 AC 42 ms
49,248 KB
testcase_44 AC 42 ms
49,312 KB
testcase_45 AC 42 ms
49,456 KB
testcase_46 AC 42 ms
49,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class No197 {

    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    System.in));
            String SBefore = br.readLine();
            int N = Integer.parseInt(br.readLine());
            String SAfter = br.readLine();
            if (dfs(N % 4, SBefore, SAfter)) {
                System.out.println("FAILURE");
            } else {
                System.out.println("SUCCESS");
            }

        } catch (Exception e) {
            System.err.println("Error:" + e.getMessage());
        }
    }

    static boolean dfs(int N, String S, String SAfter) {
        if (N == 0) {
            if (S.equals(SAfter)) {
                return true;
            } else {
                return false;
            }
        }

        if (dfs(N - 1, swap(S, true), SAfter)) {
            return true;
        }

        if (dfs(N - 1, swap(S, false), SAfter)) {
            return true;
        }

        return false;
    }

    // trueなら左
    // falseなら右
    static String swap(String S, boolean changeSide) {
        char[] c = S.toCharArray();
        char swap = c[1];
        if (changeSide) {
            c[1] = c[0];
            c[0] = swap;
        } else {
            c[1] = c[2];
            c[2] = swap;
        }

        return new String(c);

    }

}
0