結果

問題 No.29 パワーアップ
ユーザー 明智重蔵
提出日時 2015-07-18 11:56:53
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 35 ms / 5,000 ms
コード長 1,692 bytes
コンパイル時間 873 ms
コンパイル使用メモリ 117,820 KB
実行使用メモリ 19,840 KB
最終ジャッジ日時 2024-07-08 10:08:20
合計ジャッジ時間 2,329 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

class Program
{
    static string InputPattern = "Input4";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("5");
            WillReturn.Add("1 2 3");
            WillReturn.Add("4 5 6");
            WillReturn.Add("7 8 9");
            WillReturn.Add("10 1 2");
            WillReturn.Add("3 4 5");
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("3");
            WillReturn.Add("1 1 1");
            WillReturn.Add("1 1 1");
            WillReturn.Add("1 1 1");
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("3");
            WillReturn.Add("1 2 3");
            WillReturn.Add("5 4 1");
            WillReturn.Add("1 9 2");
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        IEnumerable<int> EnumItem =
            InputList.Skip(1).SelectMany(X => X.Split(' '), (X, Y) => int.Parse(Y));

        int PowerUpCnt = 0;

        //アイテムごとのCountを求める
        var Query = EnumItem.GroupBy(X => X).Select(X => new { X.Key, cnt = X.Count() });

        //同じアイテムが2つあればパワーアップ
        PowerUpCnt += Query.Sum(X => X.cnt / 2);

        //アイテムを4つ使ってパワーアップ
        PowerUpCnt += Query.Sum(X => X.cnt % 2) / 4;

        Console.WriteLine(PowerUpCnt);
    }
}
0