結果
| 問題 |
No.1592 Tenkei 90
|
| コンテスト | |
| ユーザー |
NASU41
|
| 提出日時 | 2021-05-04 13:38:27 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,353 bytes |
| コンパイル時間 | 2,315 ms |
| コンパイル使用メモリ | 79,372 KB |
| 実行使用メモリ | 56,540 KB |
| 最終ジャッジ日時 | 2024-07-01 14:13:42 |
| 合計ジャッジ時間 | 6,285 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 12 WA * 5 |
ソースコード
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;
}
}
NASU41