結果
問題 | No.233 めぐるはめぐる (3) |
ユーザー | silviasetitech |
提出日時 | 2020-03-15 19:56:22 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 901 ms / 1,000 ms |
コード長 | 3,692 bytes |
コンパイル時間 | 2,414 ms |
コンパイル使用メモリ | 79,128 KB |
実行使用メモリ | 85,636 KB |
最終ジャッジ日時 | 2024-05-04 02:57:29 |
合計ジャッジ時間 | 12,612 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 666 ms
74,876 KB |
testcase_01 | AC | 509 ms
66,500 KB |
testcase_02 | AC | 346 ms
61,972 KB |
testcase_03 | AC | 582 ms
66,416 KB |
testcase_04 | AC | 825 ms
85,616 KB |
testcase_05 | AC | 684 ms
80,704 KB |
testcase_06 | AC | 721 ms
80,900 KB |
testcase_07 | AC | 901 ms
83,596 KB |
testcase_08 | AC | 826 ms
85,636 KB |
testcase_09 | AC | 101 ms
52,996 KB |
testcase_10 | AC | 116 ms
53,960 KB |
testcase_11 | AC | 118 ms
54,112 KB |
testcase_12 | AC | 519 ms
66,564 KB |
testcase_13 | AC | 668 ms
74,788 KB |
ソースコード
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.HashSet; import java.util.Scanner; import java.util.Set; /** * Built using CHelper plug-in * Actual solution is at the top * * @author silviase */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); inabameguru solver = new inabameguru(); solver.solve(1, in, out); out.close(); } static class inabameguru { public void solve(int testNumber, Scanner in, PrintWriter out) { Operation o = new Operation(); int n = in.nextInt(); Set<String> hs = new HashSet<>(); for (int i = 0; i < n; i++) { String s = in.next(); hs.add(s); } int[] mot = {97, 97, 101, 105, 117, 117}; int[] chi = {0, 98, 103, 109, 110, 114}; int[] res = new int[12]; for (int i = 0; i < 6; i++) { res[2 * i] = chi[i]; res[2 * i + 1] = mot[i]; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < 12; i++) { if (res[i] != 0) { sb.append((char) res[i]); } } String cmp = sb.toString(); if (!hs.contains(cmp)) { out.println(cmp); return; } while (o.nextPermutation(mot) != null) { chi[0] = 0; chi[1] = 98; chi[2] = 103; chi[3] = 109; chi[4] = 110; chi[5] = 114; while (o.nextPermutation(chi) != null) { for (int i = 0; i < 6; i++) { res[2 * i] = chi[i]; res[2 * i + 1] = mot[i]; } sb = new StringBuilder(); for (int i = 0; i < 12; i++) { if (res[i] != 0) { sb.append((char) res[i]); } } cmp = sb.toString(); if (!hs.contains(cmp)) { out.println(cmp); return; } } } out.println("NO"); } } static class Operation { public int[] nextPermutation(int[] array) { int k = -1; int i = array.length - 2; while (i >= 0) { if (array[i] < array[i + 1]) { k = i; break; } i--; } // 存在しない場合nullを返す if (k == -1) return null; int l = k + 1; i = array.length - 1; while (i > k + 1) { if (array[k] < array[i]) { l = i; break; } i--; } int tmp = array[k]; array[k] = array[l]; array[l] = tmp; int[] res = new int[array.length]; // k+1 <-> n-1 for (int j = k + 1; j < array.length + k - j; j++) { tmp = array[j]; array[j] = array[array.length + k - j]; array[array.length + k - j] = tmp; } return array; } } }