結果
問題 | No.133 カードゲーム |
ユーザー | Oland |
提出日時 | 2018-11-07 15:46:30 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 148 ms / 5,000 ms |
コード長 | 1,448 bytes |
コンパイル時間 | 2,289 ms |
コンパイル使用メモリ | 78,160 KB |
実行使用メモリ | 54,716 KB |
最終ジャッジ日時 | 2024-04-30 22:25:10 |
合計ジャッジ時間 | 6,530 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 144 ms
54,716 KB |
testcase_01 | AC | 141 ms
54,316 KB |
testcase_02 | AC | 148 ms
54,088 KB |
testcase_03 | AC | 140 ms
54,268 KB |
testcase_04 | AC | 139 ms
54,260 KB |
testcase_05 | AC | 140 ms
54,308 KB |
testcase_06 | AC | 144 ms
54,396 KB |
testcase_07 | AC | 142 ms
54,260 KB |
testcase_08 | AC | 140 ms
54,304 KB |
testcase_09 | AC | 140 ms
54,016 KB |
testcase_10 | AC | 143 ms
54,412 KB |
testcase_11 | AC | 138 ms
54,212 KB |
testcase_12 | AC | 143 ms
54,368 KB |
testcase_13 | AC | 140 ms
53,980 KB |
testcase_14 | AC | 141 ms
54,244 KB |
testcase_15 | AC | 140 ms
54,360 KB |
testcase_16 | AC | 142 ms
54,208 KB |
testcase_17 | AC | 142 ms
53,864 KB |
testcase_18 | AC | 141 ms
54,208 KB |
testcase_19 | AC | 147 ms
54,224 KB |
testcase_20 | AC | 141 ms
54,020 KB |
testcase_21 | AC | 143 ms
54,372 KB |
testcase_22 | AC | 142 ms
54,164 KB |
ソースコード
import java.io.File; import java.io.IOException; import java.util.*; public class Main { public static void main(String[] args) throws IOException { //File file = new File("input.txt"); //Scanner sc = new Scanner(file); Scanner sc = new Scanner(System.in); 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(); ArrayList<Integer> list = new ArrayList<Integer>(); int[] d = dfs(list, A, B, N); //System.out.println(d[0] + " " + d[1] + " "); System.out.println((1.0 * d[0] / d[1])); } public static int[] dfs(ArrayList<Integer> cardIndexList, int[] A, int[] B, int N){ int winNum = 0; int battleNum = 0; if(cardIndexList.size() == N){ int count = 0; for(int i = 0; i < N; i++){ //System.out.print(A[cardIndexList.get(i)]); if(A[cardIndexList.get(i)] > B[i]) count++; if(A[cardIndexList.get(i)] < B[i]) count--; } //System.out.println(); battleNum = 1; if(count >= 1) winNum = 1; else winNum = 0; }else{ for(int i = 0; i < N; i++){ if(!cardIndexList.contains(i)){ ArrayList<Integer> nextList = new ArrayList<Integer>(); for(Integer m : cardIndexList) nextList.add(m); nextList.add(i); int[] d = dfs(nextList, A, B, N); winNum += d[0]; battleNum += d[1]; } } } int[] d = {winNum, battleNum}; return d; } }