結果

問題 No.133 カードゲーム
ユーザー threecoursethreecourse
提出日時 2018-08-11 12:36:25
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 33 ms / 5,000 ms
コード長 3,336 bytes
コンパイル時間 922 ms
コンパイル使用メモリ 111,152 KB
実行使用メモリ 26,292 KB
最終ジャッジ日時 2023-10-24 13:49:06
合計ジャッジ時間 2,449 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
26,268 KB
testcase_01 AC 30 ms
26,268 KB
testcase_02 AC 30 ms
26,268 KB
testcase_03 AC 29 ms
25,460 KB
testcase_04 AC 30 ms
26,292 KB
testcase_05 AC 30 ms
26,292 KB
testcase_06 AC 30 ms
26,292 KB
testcase_07 AC 30 ms
26,292 KB
testcase_08 AC 30 ms
26,292 KB
testcase_09 AC 30 ms
26,292 KB
testcase_10 AC 30 ms
26,292 KB
testcase_11 AC 30 ms
26,292 KB
testcase_12 AC 30 ms
26,292 KB
testcase_13 AC 30 ms
26,268 KB
testcase_14 AC 30 ms
26,292 KB
testcase_15 AC 30 ms
26,292 KB
testcase_16 AC 30 ms
26,292 KB
testcase_17 AC 29 ms
25,472 KB
testcase_18 AC 30 ms
26,292 KB
testcase_19 AC 30 ms
26,292 KB
testcase_20 AC 31 ms
26,292 KB
testcase_21 AC 30 ms
26,292 KB
testcase_22 AC 30 ms
26,292 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.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public int[] A, B;
        public int count;
        public int win;
        public List<int[]> orders;
        public void Run()
        {
            N = Input.ReadInt();
            A = Input.ReadIntArray();
            B = Input.ReadIntArray();

            orders = new List<int[]>();
            count = 0;
            win = 0;
            var pm = new Permutation(N, Process);
            pm.DFSRun();

            for (int i = 0; i < orders.Count; i++)
                for(int j = 0; j < orders.Count; j++)
                {
                    int w = 0;
                    int l = 0;
                    for (int k = 0; k < N; k++)
                    {
                        if (A[orders[i][k]] > B[orders[j][k]]) w++;
                        else l++;
                    }

                    if (w > l) win++;
                    count++;
                }

            Console.WriteLine(((double)win)/ count);

        }

        public void Process(int[] order)
        {
            orders.Add((int[])order.Clone());
        }

    }

    // libs ----------
    // Permutationを全通り列挙
    class Permutation
    {
        public int N;
        public bool[] F;
        public int[] V;
        public Action<int[]> Process;

        public Permutation(int N, Action<int[]> process)
        {
            this.N = N;
            Process = process;
        }

        public void DFSRun()
        {
            F = new bool[N];
            V = new int[N];
            DFS(0);
        }

        private void DFS(int i)
        {
            if (i == N)
            {
                Process(V);
            }
            else
            {
                for (int k = 0; k < N; k++)
                    if (!F[k])
                    {
                        F[k] = true;
                        V[i] = k;
                        DFS(i + 1);
                        F[k] = false;
                    }
            }
        }

    }

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}
0