結果

問題 No.133 カードゲーム
ユーザー yuya178yuya178
提出日時 2017-06-22 00:17:39
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,387 bytes
コンパイル時間 2,514 ms
コンパイル使用メモリ 78,864 KB
実行使用メモリ 50,644 KB
最終ジャッジ日時 2024-04-10 10:05:27
合計ジャッジ時間 4,392 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 52 ms
50,048 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 52 ms
50,212 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
    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);
            out.println(res);
        }

        public int game(int a[], int b[],int win){
            if(a.length==1){
                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