結果

問題 No.1592 Tenkei 90
ユーザー NASU41NASU41
提出日時 2021-05-04 13:38:27
言語 Java21
(openjdk 21)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,353 bytes
コンパイル時間 2,347 ms
コンパイル使用メモリ 75,304 KB
実行使用メモリ 58,460 KB
最終ジャッジ日時 2023-09-14 06:45:20
合計ジャッジ時間 6,173 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 141 ms
57,808 KB
testcase_06 AC 139 ms
56,240 KB
testcase_07 AC 140 ms
58,396 KB
testcase_08 AC 139 ms
57,648 KB
testcase_09 AC 138 ms
58,404 KB
testcase_10 AC 140 ms
58,116 KB
testcase_11 AC 142 ms
58,196 KB
testcase_12 AC 140 ms
57,756 KB
testcase_13 AC 142 ms
58,132 KB
testcase_14 AC 143 ms
57,760 KB
testcase_15 AC 143 ms
58,460 KB
testcase_16 AC 142 ms
57,952 KB
testcase_17 WA -
testcase_18 AC 143 ms
57,852 KB
testcase_19 AC 146 ms
58,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    private static boolean match(String s, int[] perm, String target){
        if(s.length() != target.length()) return false;
        for(int i=0; i<s.length(); i++){
            if(s.charAt(perm[i]) != target.charAt(i)) return false;
        }
        return true;
    }
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        boolean found = false;
        //全ての並べ替え方を試します. 8! = 40320[通り]程度なので十分間に合います
        //(参考) 10!でかなりきつい, 12!は無理筋と思ったほうがいいかも
        for(int[] perm: new Permutation("redcoder".length())){
            if(match(s, perm, "redcoder")) found = true;
        }
        System.out.println(found ? "Yes" : "No");
    }
}
/*以下, ACLibraryForJavaを利用. 内部実装が気になる人以外は読まなくてOKです*/
/*ドキュメントはこちら→ https://github.com/NASU41/AtCoderLibraryForJava/tree/master/Permutation */
class Permutation implements java.util.Iterator<int[]>, Iterable<int[]> {
    private int[] next;

    public Permutation(int n) {
        next = java.util.stream.IntStream.range(0, n).toArray();
    }

    @Override
    public boolean hasNext() {
        return next != null;
    }

    @Override
    public int[] next() {
        int[] r = next.clone();
        next = nextPermutation(next);
        return r;
    }

    @Override
    public java.util.Iterator<int[]> iterator() {
        return this;
    }

    public static int[] nextPermutation(int[] a) {
        if (a == null || a.length < 2)
            return null;
        int p = 0;
        for (int i = a.length - 2; i >= 0; i--) {
            if (a[i] >= a[i + 1])
                continue;
            p = i;
            break;
        }
        int q = 0;
        for (int i = a.length - 1; i > p; i--) {
            if (a[i] <= a[p])
                continue;
            q = i;
            break;
        }
        if (p == 0 && q == 0)
            return null;
        int temp = a[p];
        a[p] = a[q];
        a[q] = temp;
        int l = p, r = a.length;
        while (++l < --r) {
            temp = a[l];
            a[l] = a[r];
            a[r] = temp;
        }
        return a;
    }
}
0