結果

問題 No.133 カードゲーム
ユーザー yuya178yuya178
提出日時 2017-06-22 00:26:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 3,549 bytes
コンパイル時間 2,119 ms
コンパイル使用メモリ 74,792 KB
実行使用メモリ 50,040 KB
最終ジャッジ日時 2023-09-07 09:31:52
合計ジャッジ時間 3,477 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
47,636 KB
testcase_01 AC 37 ms
49,360 KB
testcase_02 AC 36 ms
49,372 KB
testcase_03 AC 35 ms
49,580 KB
testcase_04 AC 36 ms
49,476 KB
testcase_05 AC 38 ms
49,552 KB
testcase_06 AC 42 ms
49,772 KB
testcase_07 AC 41 ms
50,040 KB
testcase_08 AC 40 ms
49,872 KB
testcase_09 AC 37 ms
49,576 KB
testcase_10 AC 37 ms
49,508 KB
testcase_11 AC 37 ms
49,500 KB
testcase_12 AC 37 ms
49,440 KB
testcase_13 AC 36 ms
49,508 KB
testcase_14 AC 37 ms
49,824 KB
testcase_15 AC 38 ms
49,356 KB
testcase_16 AC 40 ms
49,900 KB
testcase_17 AC 38 ms
49,372 KB
testcase_18 AC 38 ms
47,664 KB
testcase_19 AC 38 ms
49,608 KB
testcase_20 AC 37 ms
49,708 KB
testcase_21 AC 37 ms
49,584 KB
testcase_22 AC 36 ms
49,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    static int N;
    static int t;
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            N = in.nextInt();
            int[] A = new int[N];
            int[] B = new int[N];
            for(int i=0; i<N; i++){
                A[i] = in.nextInt();
            }
            for(int i=0; i<N; i++){
                B[i] = in.nextInt();
            }
            int win=0;
            int res = game(A,B,win);
            // int t = 1;
            // for(int i=1; i<=N; i++){
            //     t = t*i*i;
            // }
            out.println((double)res/t);
        }

        public int game(int a[], int b[],int win){
            if(a.length==1){
                t++;
                if(a[0]>b[0]) win++;
                if(2*win>N) return 1;
                else{
                    return 0;
                }
            }
            int res=0;
            int flag=0;
            for(int i=0; i<a.length; i++){
                int ca[] = new int[a.length-1];
                    int x = 0;
                    for(int k=0; k<a.length; k++){
                        if(k==i) continue;
                        ca[x] = a[k];
                        x++;
                    }
                for(int j=0; j<b.length; j++){
                    int cb[] = new int[b.length-1];
                    int y = 0;
                    for(int k=0; k<b.length; k++){
                        if(k==j) continue;
                        cb[y] = b[k];
                        y++;
                    }
                    if(a[i]>b[j]){
                        win++;
                        flag=1;
                    }
                    res+=game(ca,cb,win);
                    if(flag==1) win--;
                    flag=0;

                }
            }
            return res;
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}
0