結果

問題 No.1279 Array Battle
ユーザー keymoonkeymoon
提出日時 2020-12-31 21:17:21
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 1,630 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 109,952 KB
実行使用メモリ 23,424 KB
最終ジャッジ日時 2024-04-18 02:52:57
合計ジャッジ時間 3,249 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
19,328 KB
testcase_01 AC 36 ms
19,328 KB
testcase_02 AC 35 ms
19,456 KB
testcase_03 AC 34 ms
19,200 KB
testcase_04 AC 37 ms
19,200 KB
testcase_05 AC 35 ms
19,200 KB
testcase_06 AC 37 ms
19,328 KB
testcase_07 AC 36 ms
19,456 KB
testcase_08 AC 37 ms
19,200 KB
testcase_09 AC 36 ms
19,072 KB
testcase_10 AC 36 ms
19,456 KB
testcase_11 AC 36 ms
19,328 KB
testcase_12 AC 38 ms
20,096 KB
testcase_13 AC 47 ms
23,424 KB
testcase_14 AC 46 ms
23,424 KB
testcase_15 AC 107 ms
23,296 KB
testcase_16 AC 104 ms
23,424 KB
testcase_17 AC 97 ms
23,168 KB
testcase_18 AC 99 ms
23,424 KB
testcase_19 AC 100 ms
23,296 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;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();
        var b = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int max = 0;
        int cnt = 0;
        foreach (var item in Permutations(a.Select((x, y) => (x, y)).ToArray()))
        {
            int res = 0;
            for (int i = 0; i < n; i++) res += Max(0, item[i].x - b[i]);
            if (max < res) { max = res; cnt = 0; }
            if (max == res) cnt++;
        }
        Console.WriteLine(cnt);
    }

    static IEnumerable<T[]> Permutations<T>(T[] array) where T : IComparable<T>
    {
        int index = 0;
        yield return array;
        while (true)
        {
            for (int i = array.Length - 1; i > 0; i--)
            {
                if (array[i - 1].CompareTo(array[i]) >= 0) continue;
                int j = Array.FindLastIndex(array, x => array[i - 1].CompareTo(x) < 0);
                T tmp = array[i - 1]; array[i - 1] = array[j]; array[j] = tmp;
                Array.Reverse(array, i, array.Length - i);
                yield return array;
                goto end;
            }
            Array.Reverse(array, index, array.Length);
            yield break;
            end:;
        }
    }
}
0