結果
問題 | No.133 カードゲーム |
ユーザー | Takahiro Ishikawa |
提出日時 | 2018-10-08 20:00:05 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 126 ms / 5,000 ms |
コード長 | 2,082 bytes |
コンパイル時間 | 4,771 ms |
コンパイル使用メモリ | 78,432 KB |
実行使用メモリ | 54,272 KB |
最終ジャッジ日時 | 2024-04-20 18:48:38 |
合計ジャッジ時間 | 8,582 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 119 ms
53,988 KB |
testcase_01 | AC | 101 ms
52,712 KB |
testcase_02 | AC | 115 ms
54,056 KB |
testcase_03 | AC | 115 ms
53,916 KB |
testcase_04 | AC | 108 ms
52,908 KB |
testcase_05 | AC | 126 ms
54,108 KB |
testcase_06 | AC | 118 ms
53,980 KB |
testcase_07 | AC | 113 ms
53,556 KB |
testcase_08 | AC | 107 ms
52,940 KB |
testcase_09 | AC | 108 ms
52,704 KB |
testcase_10 | AC | 125 ms
54,112 KB |
testcase_11 | AC | 122 ms
54,212 KB |
testcase_12 | AC | 123 ms
54,008 KB |
testcase_13 | AC | 122 ms
54,080 KB |
testcase_14 | AC | 120 ms
54,112 KB |
testcase_15 | AC | 103 ms
52,700 KB |
testcase_16 | AC | 124 ms
53,964 KB |
testcase_17 | AC | 122 ms
53,872 KB |
testcase_18 | AC | 121 ms
54,084 KB |
testcase_19 | AC | 110 ms
52,800 KB |
testcase_20 | AC | 117 ms
54,272 KB |
testcase_21 | AC | 125 ms
54,184 KB |
testcase_22 | AC | 121 ms
54,096 KB |
ソースコード
import java.util.*; public class Q133 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); Integer[] a = new Integer[N]; Integer[] b = new Integer[N]; for (int i = 0; i < N; i++) { a[i] = sc.nextInt(); } for (int i = 0; i < N; i++) { b[i] = sc.nextInt(); } Integer[] na = new Integer[N]; Integer[] nb = new Integer[N]; for (int i = 0; i < N; i++) { na[i] = i; nb[i] = i; } int cnt = 0; int win = 0; do { do { int awin = 0; int bwin = 0; for (int i = 0; i < N; i++) { if (a[na[i]] > b[nb[i]]) awin++; if (b[nb[i]] > a[na[i]]) bwin++; } if (awin > bwin) win++; cnt++; } while ((nb = (Integer[]) nextPermutation(nb)) != null); nb = new Integer[N]; for (int i = 0; i < N; i++) { nb[i] = i; } } while ((na = (Integer[]) nextPermutation(na)) != null); System.out.println(1.0 * win / cnt); } private static Comparable[] nextPermutation(final Comparable[] c) { int first = _getFirst(c); if (first == -1) return null; int toSwap = c.length - 1; while (c[first].compareTo(c[toSwap]) >= 0) { toSwap--; } swap(c, first++, toSwap); toSwap = c.length - 1; while (first < toSwap) { swap(c, first++, toSwap--); } return c; } private static void swap(final Comparable[] c, final int i, final int j) { final Comparable tmp = c[i]; c[i] = c[j]; c[j] = tmp; } private static int _getFirst(final Comparable[] c) { for (int i = c.length - 2; i >= 0; i--) { if (c[i].compareTo(c[i + 1]) < 0) { return i; } } return -1; } }