結果

問題 No.133 カードゲーム
ユーザー 抹茶アイス抹茶アイス
提出日時 2023-07-20 14:03:13
言語 C#
(.NET 8.0.203)
結果
WA  
実行時間 -
コード長 2,227 bytes
コンパイル時間 20,059 ms
コンパイル使用メモリ 158,784 KB
実行使用メモリ 177,280 KB
最終ジャッジ日時 2023-10-20 14:46:52
合計ジャッジ時間 23,722 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
31,628 KB
testcase_01 AC 60 ms
31,628 KB
testcase_02 AC 61 ms
31,628 KB
testcase_03 WA -
testcase_04 AC 61 ms
31,628 KB
testcase_05 AC 61 ms
31,644 KB
testcase_06 AC 60 ms
31,648 KB
testcase_07 AC 60 ms
31,648 KB
testcase_08 AC 61 ms
31,636 KB
testcase_09 AC 60 ms
31,636 KB
testcase_10 AC 62 ms
31,648 KB
testcase_11 AC 61 ms
31,648 KB
testcase_12 AC 61 ms
31,648 KB
testcase_13 AC 62 ms
31,636 KB
testcase_14 AC 62 ms
31,636 KB
testcase_15 AC 59 ms
31,636 KB
testcase_16 AC 61 ms
31,648 KB
testcase_17 WA -
testcase_18 AC 60 ms
31,648 KB
testcase_19 AC 61 ms
31,648 KB
testcase_20 AC 61 ms
31,648 KB
testcase_21 AC 62 ms
31,648 KB
testcase_22 AC 63 ms
177,280 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (139 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
public class Program{
    public static void Main(){
        var n = int.Parse(Console.ReadLine());
        var a = new int[n];
        var b = new int[n];
        var A = Console.ReadLine().Split(' ');
        var B = Console.ReadLine().Split(' ');
        int i;
        for(i=0;i<n;i++){
            a[i] = int.Parse(A[i]);
            b[i] = int.Parse(B[i]);
        }
        Array.Sort(a);
        Array.Sort(b);
        var AA = AllPermutation(a);
        var BB = AllPermutation(b);
        double win = 0;
        foreach(var aa in AA){
            foreach(var bb in BB){
                var awin = 0;
                var bwin = 0;
                for(i=0;i<n;i++){
                    if(aa[i]>bb[i]){
                        awin++;
                    }
                    else if(aa[i]<bb[i]){
                        bwin++;
                    }
                }
                if(awin>bwin){
                    win++;
                }
            }
        }
        if(win==0){
            Console.WriteLine(-1);
        }
        else{
            Console.WriteLine(win/Math.Pow(AA.Count,2));
        }
    }
    static List<T[]> AllPermutation<T>(params T[] array) where T : IComparable
    {
        var a = new List<T>(array).ToArray();
        var res = new List<T[]>();
        res.Add(new List<T>(a).ToArray());
        var n = a.Length;
        var next = true;
        while (next)
        {
            next = false;
    
            // 1
            int i;
            for (i = n - 2; i >= 0; i--)
            {
                if (a[i].CompareTo(a[i + 1]) < 0) break;
            }
            // 2
            if (i < 0) break;
    
            // 3
            var j = n;
            do
            {
                j--;
            } while (a[i].CompareTo(a[j]) > 0);
    
            if (a[i].CompareTo(a[j]) < 0)
            {
                // 4
                var tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
                Array.Reverse(a, i + 1, n - i - 1);
                res.Add(new List<T>(a).ToArray());
                next = true;
            }
        }
        return res;
    }
}
0