結果
問題 | No.133 カードゲーム |
ユーザー | Takahiro Ishikawa |
提出日時 | 2018-10-08 19:38:12 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,066 bytes |
コンパイル時間 | 2,111 ms |
コンパイル使用メモリ | 79,300 KB |
実行使用メモリ | 41,728 KB |
最終ジャッジ日時 | 2024-04-20 18:45:36 |
合計ジャッジ時間 | 5,570 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 112 ms
41,224 KB |
testcase_01 | AC | 116 ms
41,352 KB |
testcase_02 | AC | 120 ms
41,600 KB |
testcase_03 | AC | 106 ms
40,192 KB |
testcase_04 | WA | - |
testcase_05 | AC | 124 ms
41,272 KB |
testcase_06 | AC | 118 ms
41,352 KB |
testcase_07 | AC | 105 ms
40,232 KB |
testcase_08 | AC | 108 ms
40,288 KB |
testcase_09 | WA | - |
testcase_10 | AC | 117 ms
41,728 KB |
testcase_11 | AC | 105 ms
40,376 KB |
testcase_12 | AC | 129 ms
41,308 KB |
testcase_13 | WA | - |
testcase_14 | AC | 112 ms
41,392 KB |
testcase_15 | WA | - |
testcase_16 | AC | 107 ms
40,576 KB |
testcase_17 | AC | 107 ms
40,276 KB |
testcase_18 | WA | - |
testcase_19 | AC | 113 ms
41,380 KB |
testcase_20 | AC | 115 ms
41,168 KB |
testcase_21 | AC | 119 ms
41,352 KB |
testcase_22 | AC | 108 ms
40,072 KB |
ソースコード
import java.util.*; public class Main { 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[] bcache = new Integer[N]; for (int i = 0; i < N; i++) { bcache[i] = b[i]; } int cnt = 0; int win = 0; Arrays.sort(a); Arrays.sort(b); do { do { int awin = 0; int bwin = 0; for (int i = 0; i < N; i++) { if (a[i] > b[i]) awin++; if (b[i] > a[i]) bwin++; } if (awin > bwin) win++; cnt++; } while ((b = (Integer[]) nextPermutation(b)) != null); b = new Integer[N]; for (int i = 0; i < N; i++) { b[i] = bcache[i]; } } while ((a = (Integer[]) nextPermutation(a)) != 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; } }