結果
問題 | No.29 パワーアップ |
ユーザー |
![]() |
提出日時 | 2024-10-10 21:38:06 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 38 ms / 5,000 ms |
コード長 | 2,003 bytes |
コンパイル時間 | 1,441 ms |
コンパイル使用メモリ | 117,460 KB |
実行使用メモリ | 27,532 KB |
最終ジャッジ日時 | 2024-10-10 21:38:10 |
合計ジャッジ時間 | 3,177 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;using System.Collections.Generic;using System.Linq;class Program{static string InputPattern = "InputX";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");//6//アイテム1,2,3,4,5が2つ揃ったので パワーアップを5回できる。//さらにアイテム 6,7,8,9を使い、更にパワーアップするでき、//合計6回パワーアップすることができる。}else if (InputPattern == "Input2") {WillReturn.Add("3");WillReturn.Add("1 1 1");WillReturn.Add("1 1 1");WillReturn.Add("1 1 1");//4}else if (InputPattern == "Input3") {WillReturn.Add("3");WillReturn.Add("1 2 3");WillReturn.Add("5 4 1");WillReturn.Add("1 9 2");//3}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);}}