結果

問題 No.133 カードゲーム
ユーザー nanophoto12nanophoto12
提出日時 2015-01-28 01:37:32
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 72 ms / 5,000 ms
コード長 2,227 bytes
コンパイル時間 3,218 ms
コンパイル使用メモリ 103,756 KB
実行使用メモリ 27,724 KB
最終ジャッジ日時 2023-09-07 09:11:07
合計ジャッジ時間 5,957 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
25,832 KB
testcase_01 AC 71 ms
23,696 KB
testcase_02 AC 70 ms
25,496 KB
testcase_03 AC 65 ms
23,812 KB
testcase_04 AC 70 ms
23,464 KB
testcase_05 AC 71 ms
23,592 KB
testcase_06 AC 70 ms
23,584 KB
testcase_07 AC 70 ms
23,764 KB
testcase_08 AC 69 ms
23,640 KB
testcase_09 AC 70 ms
23,796 KB
testcase_10 AC 70 ms
23,720 KB
testcase_11 AC 70 ms
23,720 KB
testcase_12 AC 72 ms
27,724 KB
testcase_13 AC 71 ms
23,636 KB
testcase_14 AC 72 ms
23,592 KB
testcase_15 AC 70 ms
21,788 KB
testcase_16 AC 71 ms
25,676 KB
testcase_17 AC 67 ms
21,904 KB
testcase_18 AC 70 ms
23,600 KB
testcase_19 AC 69 ms
23,512 KB
testcase_20 AC 69 ms
23,556 KB
testcase_21 AC 69 ms
23,608 KB
testcase_22 AC 70 ms
23,712 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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

namespace YukiCoder2
{
    class Program
    {
        public static bool NextPermutation<T>(T[] array, int start, int length)
            where T : IComparable
        {
            int end = start + length - 1;

            if (end <= start) return false;

            int last = end;
            while (true)
            {
                int pos = last--;

                if (array[last].CompareTo(array[pos]) < 0)
                {
                    int i;
                    for (i = end + 1; array[last].CompareTo(array[--i]) >= 0; ) { }
                    T tmp = array[last]; array[last] = array[i]; array[i] = tmp;
                    Array.Reverse(array, pos, end - pos + 1);
                    return true;
                }
                if (last == start)
                {
                    Array.Reverse(array, start, end - start);
                    return false;
                }
            }

            throw new Exception("NextPermutation: Fatal error");
        }

        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var n = line[0];
            var aCards = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(aCards);
            var bCards = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(bCards);
            int sum = 0;
            int total = 0;
            do
            {
                var bCopy = bCards.ToArray();
                do
                {
                    int win = 0;
                    for (int i = 0; i < n; i++)
                    {
                        if (aCards[i] > bCopy[i])
                        {
                            win++;
                        }
                    }
                    if (win > n/2)
                    {
                        sum++;
                    }
                    total++;
                } while (NextPermutation(bCopy, 0, n));
            } while (NextPermutation(aCards, 0, n));


            Console.WriteLine(sum / (double)total);
        }
    }
}
0