結果

問題 No.133 カードゲーム
ユーザー tsunabittsunabit
提出日時 2020-03-04 21:06:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 153 ms / 5,000 ms
コード長 1,191 bytes
コンパイル時間 3,251 ms
コンパイル使用メモリ 79,136 KB
実行使用メモリ 42,632 KB
最終ジャッジ日時 2024-04-22 01:52:08
合計ジャッジ時間 7,371 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
42,272 KB
testcase_01 AC 133 ms
42,632 KB
testcase_02 AC 144 ms
42,532 KB
testcase_03 AC 111 ms
41,116 KB
testcase_04 AC 146 ms
42,584 KB
testcase_05 AC 139 ms
42,496 KB
testcase_06 AC 150 ms
42,524 KB
testcase_07 AC 139 ms
42,260 KB
testcase_08 AC 124 ms
41,916 KB
testcase_09 AC 134 ms
42,264 KB
testcase_10 AC 136 ms
42,364 KB
testcase_11 AC 142 ms
42,588 KB
testcase_12 AC 132 ms
41,968 KB
testcase_13 AC 142 ms
42,332 KB
testcase_14 AC 128 ms
41,924 KB
testcase_15 AC 137 ms
42,368 KB
testcase_16 AC 145 ms
42,228 KB
testcase_17 AC 151 ms
42,296 KB
testcase_18 AC 150 ms
42,464 KB
testcase_19 AC 153 ms
42,404 KB
testcase_20 AC 147 ms
41,972 KB
testcase_21 AC 152 ms
42,484 KB
testcase_22 AC 141 ms
42,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

public class No133 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String a = "";
		for(int i = 0; i < n; i++) a += sc.next();
		String b = "";
		for(int i = 0; i < n; i++) b += sc.next();
		
		ArrayList<String> al = new ArrayList<String>();
		permutation(a, "", al);
		ArrayList<String> bl = new ArrayList<String>();
		permutation(b, "", bl);
		
		int t = 0;
		int ans = 0;
		for(int i = 0; i < al.size(); i++) {
			for(int j = 0; j < al.size(); j++) {
				for(int k = 0; k < a.length(); k++) {
					if((int)al.get(i).charAt(k) > (int)bl.get(j).charAt(k)) {
						t++;
					}
				}
				if(t > n/2) ans++;
				t = 0;
			}
		}
		System.out.println((double)ans / (al.size() * bl.size()));
		
	}
	public static void permutation(String q, String ans, ArrayList<String> al){
        // Base Case
        if(q.length() <= 1) {
            al.add(ans+q);
        }
        // General Case
        else {
            for (int i = 0; i < q.length(); i++) {
                permutation(q.substring(0, i) + q.substring(i + 1), ans + q.charAt(i), al);
            }
        }
    }
}
0