結果

問題 No.133 カードゲーム
ユーザー sekiya9311sekiya9311
提出日時 2017-10-11 19:39:09
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 69 ms / 5,000 ms
コード長 4,385 bytes
コンパイル時間 4,881 ms
コンパイル使用メモリ 108,160 KB
実行使用メモリ 25,652 KB
最終ジャッジ日時 2023-09-07 10:01:01
合計ジャッジ時間 7,185 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
23,828 KB
testcase_01 AC 67 ms
23,596 KB
testcase_02 AC 68 ms
23,616 KB
testcase_03 AC 64 ms
23,828 KB
testcase_04 AC 67 ms
23,712 KB
testcase_05 AC 67 ms
23,664 KB
testcase_06 AC 67 ms
23,704 KB
testcase_07 AC 66 ms
23,548 KB
testcase_08 AC 67 ms
23,428 KB
testcase_09 AC 66 ms
23,740 KB
testcase_10 AC 67 ms
25,604 KB
testcase_11 AC 66 ms
23,560 KB
testcase_12 AC 66 ms
23,616 KB
testcase_13 AC 66 ms
23,776 KB
testcase_14 AC 67 ms
23,604 KB
testcase_15 AC 67 ms
23,508 KB
testcase_16 AC 66 ms
21,668 KB
testcase_17 AC 64 ms
23,664 KB
testcase_18 AC 67 ms
23,616 KB
testcase_19 AC 67 ms
23,684 KB
testcase_20 AC 67 ms
25,652 KB
testcase_21 AC 67 ms
23,624 KB
testcase_22 AC 69 ms
25,556 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;
using System.Threading.Tasks;

namespace ProgrammingContest
{
    class MainClass
    {
        Scanner sc;
        static void Main(string[] args)
        {
            new MainClass().Solve();
        }

        void Solve()
        {
#if DEBUG
            string backPath = "..";
            char dirSep = System.IO.Path.DirectorySeparatorChar;
            string inFilePath = backPath + dirSep + backPath + dirSep + "in.txt";
            sc = new Scanner(new System.IO.StreamReader(inFilePath));
#else
            sc = new Scanner();
#endif

            int n = sc.NextInt;
            int[] a = new int[n].Select(val => sc.NextInt).ToArray();
            int[] b = new int[n].Select(val => sc.NextInt).ToArray();
            int[] sel = new int[n];
            for (int i = 0; i < n; i++)
            {
                sel[i] = i;
            }
            int win = 0, allCnt = 0;
            do
            {
                int cnt = 0;
                for (int i = 0; i < n; i++)
                {
                    if (a[sel[i]] > b[i])
                    {
                        cnt++;
                    }
                }
                if (cnt * 2 > n)
                {
                    win++;
                }
                allCnt++;
                //Write(ArrayToString(sel));
            } while (NextPermutation(sel));
            Write(1.0 * win / allCnt);
        }

        bool NextPermutation<T>(T[] ar) where T : IComparable<T>
        {
            int left = ar.Length - 1;
            Func<int, int, int> compForCalcNextPermutation = (i, j) =>
            {
                return ar[i].CompareTo(ar[j]);
            };
            while (0 < left && compForCalcNextPermutation(left - 1, left) >= 0)
            {
                left--;
            }
            if (left == 0)
            {
                return false;
            }
            int right = ar.Length - 1;
            while (compForCalcNextPermutation(right, left - 1) <= 0)
            {
                right--;
            }
            Swap(ref ar[left - 1], ref ar[right]);
            right = ar.Length - 1;
            while (left < right)
            {
                Swap(ref ar[left], ref ar[right]);
                left++;
                right--;
            }
            return true;
        }
        void Write(object val)
        {
            Console.WriteLine(val.ToString());
        }
        void Write(string format, params object[] vals)
        {
            Console.WriteLine(format, vals);
        }
        void Swap<T>(ref T a, ref T b)
        {
            T tmp = a;
            a = b;
            b = tmp;
        }
        string ArrayToString<T>(T[] ar, string sep = " ")
        {
            return string.Join(sep, Array.ConvertAll(ar, el => el.ToString()));
        }

    }
    class Scanner
    {
        Queue<String> buffer;
        char[] sep;
        System.IO.TextReader reader;
        public Scanner(System.IO.TextReader reader = null)
        {
            this.buffer = new Queue<string>();
            this.sep = new char[] { ' ' };
            this.reader = (reader ?? Console.In);
        }
        private void CheckBuffer()
        {
            if (this.buffer.Count == 0 && this.reader.Peek() >= 0)
            {
                string[] sreArray = this.reader.ReadLine().Split(this.sep);
                foreach (String elStr in sreArray)
                {
                    this.buffer.Enqueue(elStr);
                }
            }
        }

        public String Next
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Dequeue();
            }
        }

        public int NextInt
        {
            get
            {
                return int.Parse(this.Next);
            }
        }
        public double NextDouble
        {
            get
            {
                return double.Parse(this.Next);
            }
        }

        public long NextLong
        {
            get
            {
                return long.Parse(this.Next);
            }
        }
        public bool IsEmpty
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Count == 0;
            }
        }
    }
}
0