結果
問題 | No.133 カードゲーム |
ユーザー | Grenache |
提出日時 | 2016-02-11 17:57:59 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 130 ms / 5,000 ms |
コード長 | 3,935 bytes |
コンパイル時間 | 4,224 ms |
コンパイル使用メモリ | 81,024 KB |
実行使用メモリ | 41,648 KB |
最終ジャッジ日時 | 2024-06-25 03:42:58 |
合計ジャッジ時間 | 7,992 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 115 ms
40,076 KB |
testcase_01 | AC | 115 ms
40,024 KB |
testcase_02 | AC | 127 ms
41,648 KB |
testcase_03 | AC | 114 ms
40,004 KB |
testcase_04 | AC | 114 ms
40,004 KB |
testcase_05 | AC | 115 ms
40,296 KB |
testcase_06 | AC | 115 ms
40,064 KB |
testcase_07 | AC | 116 ms
40,112 KB |
testcase_08 | AC | 116 ms
40,272 KB |
testcase_09 | AC | 114 ms
39,988 KB |
testcase_10 | AC | 130 ms
41,284 KB |
testcase_11 | AC | 130 ms
41,344 KB |
testcase_12 | AC | 116 ms
40,184 KB |
testcase_13 | AC | 115 ms
40,004 KB |
testcase_14 | AC | 121 ms
40,348 KB |
testcase_15 | AC | 128 ms
41,104 KB |
testcase_16 | AC | 118 ms
40,152 KB |
testcase_17 | AC | 127 ms
41,088 KB |
testcase_18 | AC | 128 ms
41,172 KB |
testcase_19 | AC | 115 ms
39,896 KB |
testcase_20 | AC | 116 ms
40,060 KB |
testcase_21 | AC | 118 ms
40,160 KB |
testcase_22 | AC | 127 ms
41,104 KB |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Deque; import java.util.Iterator; import java.util.List; public class Main_yukicoder133 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int n = sc.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { b[i] = sc.nextInt(); } int win = 0; int cnt = 0; Permutation np = new Permutation(n); for (List<Integer> perm : np) { if (perm == null) { break; } // System.out.println(perm); int awin = 0; for (int i = 0; i < n; i++) { if (a[i] > b[perm.get(i)]) { awin++; } else if (a[i] < b[perm.get(i)]) { awin--; } } if (awin > 0) { win++; } cnt++; } pr.printf("%.3f\n", (double)win / cnt); pr.close(); sc.close(); } private static class Permutation implements Iterable<List<Integer>>{ int n; boolean[] used; List<Integer> perm; Deque<Integer> ist; PermutationIterator it; Permutation(int n) { this.n = n; used = new boolean[n]; perm = new ArrayList<Integer>(); ist = new ArrayDeque<Integer>(); ist.add(-1); it = new PermutationIterator(this); } List<Integer> next() { out: while (!ist.isEmpty()) { int k = ist.pop(); if (k != -1) { // ループ途中での戻り used[k] = false; perm.remove(perm.size() - 1); } else { // 最初から int pos = perm.size(); if (pos == n) { // perm に対する操作 ========================= return perm; // perm に対する操作 ========================= } } for (int i = k + 1; i < n; i++) { if (!used[i]) { ist.push(i); used[i] = true; perm.add(i); ist.push(-1); continue out; } } } return null; } @Override public Iterator<List<Integer>> iterator() { return it; } private static class PermutationIterator implements Iterator<List<Integer>> { Permutation p; PermutationIterator(Permutation p) { this.p = p; } @Override public boolean hasNext() { return !p.ist.isEmpty(); } @Override public List<Integer> next() { return p.next(); } } } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }