結果

問題 No.133 カードゲーム
ユーザー bluemeganebluemegane
提出日時 2020-09-10 20:31:49
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 64 ms / 5,000 ms
コード長 1,667 bytes
コンパイル時間 2,579 ms
コンパイル使用メモリ 68,284 KB
実行使用メモリ 25,608 KB
最終ジャッジ日時 2023-08-25 14:36:50
合計ジャッジ時間 4,091 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
23,504 KB
testcase_01 AC 59 ms
23,632 KB
testcase_02 AC 61 ms
23,640 KB
testcase_03 AC 57 ms
23,832 KB
testcase_04 AC 60 ms
23,540 KB
testcase_05 AC 58 ms
25,524 KB
testcase_06 AC 62 ms
23,572 KB
testcase_07 AC 63 ms
23,556 KB
testcase_08 AC 59 ms
23,752 KB
testcase_09 AC 59 ms
25,608 KB
testcase_10 AC 61 ms
23,468 KB
testcase_11 AC 58 ms
25,516 KB
testcase_12 AC 58 ms
23,560 KB
testcase_13 AC 61 ms
25,548 KB
testcase_14 AC 64 ms
23,696 KB
testcase_15 AC 58 ms
25,564 KB
testcase_16 AC 60 ms
25,520 KB
testcase_17 AC 57 ms
23,640 KB
testcase_18 AC 61 ms
25,504 KB
testcase_19 AC 59 ms
21,552 KB
testcase_20 AC 57 ms
21,628 KB
testcase_21 AC 62 ms
23,584 KB
testcase_22 AC 59 ms
25,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Linq;
using System.Collections.Generic;
using System;

public static class Permi
{
    public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> items, int? k = null)
    {
        if (k == null) k = items.Count();
        if (k == 0) yield return Enumerable.Empty<T>();
        else
        {
            var i = 0;
            foreach (var x in items)
            {
                var xs = items.Where((_, index) => i != index);
                foreach (var c in Perm(xs, k - 1))
                    yield return c.Before(x);
                i++;
            }
        }
    }
    public static IEnumerable<T> Before<T>(this IEnumerable<T> items, T first)
    {
        yield return first;
        foreach (var i in items) yield return i;
    }
}

public class Hello
{
    public static int[] b;
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        line = Console.ReadLine().Trim().Split(' ');
        b = Array.ConvertAll(line, int.Parse);
        getAns(n, a);
    }
    static bool IsWin(int n, int[] a)
    {
        var count = 0;
        for (int i = 0; i < n; i++)
        {
            if (a[i] > b[i]) count++;
        }
        return count > n - count;
    }
    static void getAns(int n, int[] a)
    {
        var count = 0;
        var total = 0;
        var a2 = a.Perm();
        foreach (var x in a2)
        {
            total++;
            var c = x.ToArray();
            if (IsWin(n, c)) count++;
        }
        Console.WriteLine((double)count / total);
    }
}
0