結果
| 問題 | No.1279 Array Battle | 
| コンテスト | |
| ユーザー |  bluemegane | 
| 提出日時 | 2020-11-07 09:19:00 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,503 ms / 2,000 ms | 
| コード長 | 1,707 bytes | 
| コンパイル時間 | 3,311 ms | 
| コンパイル使用メモリ | 114,268 KB | 
| 実行使用メモリ | 33,512 KB | 
| 最終ジャッジ日時 | 2024-07-22 14:21:10 | 
| 合計ジャッジ時間 | 11,398 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 20 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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
{
    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(' ');
        var b = Array.ConvertAll(line, int.Parse);
        getAns(n, a, b);
    }
    static int calc(int n, int[] a, int[] b)
    {
        var res = 0;
        for (int i = 0; i < n; i++)
        {
            if (a[i] > b[i]) res += a[i] - b[i];
        }
        return res;
    }
    static void getAns(int n, int[] a, int[] b)
    {
        var count = 0;
        var maxpoint = -1;
        foreach (var x in a.Perm(n))
        {
            var a2 = x.ToArray();
            var w = calc(n, a2, b);
            if (w > maxpoint) { maxpoint = w; count = 1; }
            else if (w == maxpoint) count++;
        }
        Console.WriteLine(count);
    }
}
            
            
            
        