結果
問題 | No.133 カードゲーム |
ユーザー | kohaku_kohaku |
提出日時 | 2016-12-09 11:08:54 |
言語 | Java19 (openjdk 21) |
結果 |
AC
|
実行時間 | 166 ms / 5,000 ms |
コード長 | 1,740 bytes |
コンパイル時間 | 4,905 ms |
コンパイル使用メモリ | 75,992 KB |
実行使用メモリ | 57,120 KB |
最終ジャッジ日時 | 2023-09-07 09:27:24 |
合計ジャッジ時間 | 7,209 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 162 ms
56,756 KB |
testcase_01 | AC | 165 ms
56,920 KB |
testcase_02 | AC | 163 ms
54,696 KB |
testcase_03 | AC | 164 ms
56,912 KB |
testcase_04 | AC | 161 ms
56,892 KB |
testcase_05 | AC | 164 ms
56,808 KB |
testcase_06 | AC | 161 ms
57,048 KB |
testcase_07 | AC | 163 ms
56,908 KB |
testcase_08 | AC | 162 ms
56,608 KB |
testcase_09 | AC | 163 ms
56,732 KB |
testcase_10 | AC | 161 ms
56,820 KB |
testcase_11 | AC | 162 ms
56,720 KB |
testcase_12 | AC | 165 ms
56,920 KB |
testcase_13 | AC | 157 ms
56,776 KB |
testcase_14 | AC | 158 ms
56,448 KB |
testcase_15 | AC | 161 ms
57,120 KB |
testcase_16 | AC | 166 ms
56,608 KB |
testcase_17 | AC | 163 ms
56,996 KB |
testcase_18 | AC | 160 ms
57,012 KB |
testcase_19 | AC | 162 ms
57,108 KB |
testcase_20 | AC | 162 ms
56,852 KB |
testcase_21 | AC | 161 ms
56,724 KB |
testcase_22 | AC | 161 ms
56,452 KB |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { 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(); } int L=1; for(int i=1; i<=N; i++){ L*=i; } int win=0; String [] perm = new String [L]; makePerm(0, new int [N], new boolean [N+1], perm); for(int i=0; i<L; i++){ char [] x = perm[i].toCharArray(); int [] y = new int [N]; for(int j=0; j<N; j++){ y[j]=x[j]-'1'; } win+=judge(N,A,B,y); } double ans = (double)win/L; System.out.println(ans); } static int judge(int N, int[] A, int[] B, int[] y){ int count=0; for(int i=0; i<N; i++){ if(A[y[i]]>B[i])count++; } if(2*count>N){ return 1; }else{ return 0; } } static int k=0; static String [] makePerm(int n, int[] perm, boolean[] flag, String[] p) { if(n==perm.length){ p[k]=setPerm(perm); k++; }else{ for(int i=1; i<=perm.length; i++){ if(flag[i])continue; perm[n]=i; flag[i]=true; makePerm(n+1,perm,flag,p); flag[i]=false; } } return p; } static String setPerm(int[] perm) { String tmp=""; for (int i: perm) { tmp=i+tmp; } return tmp; } }