結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー 14番14番
提出日時 2016-04-17 05:26:07
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 230 ms / 5,000 ms
コード長 2,675 bytes
コンパイル時間 844 ms
コンパイル使用メモリ 114,636 KB
実行使用メモリ 31,516 KB
最終ジャッジ日時 2024-04-15 02:14:33
合計ジャッジ時間 2,333 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 171 ms
29,348 KB
testcase_01 AC 230 ms
29,464 KB
testcase_02 AC 106 ms
31,516 KB
testcase_03 AC 228 ms
31,248 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.Text;
using System.Linq;
 
class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int testCaceCount = int.Parse(Reader.ReadLine());
        for(int i=0; i<testCaceCount; i++) {
            int itemCount = int.Parse(Reader.ReadLine());
            Dictionary<long, int> dic = new Dictionary<long, int>();
            String[] inpt = Reader.ReadLine().Split(' ');
            foreach (String item in inpt)
            {
                long num = long.Parse(item);
                if(dic.ContainsKey(num)) {
                    dic[num]++;
                } else {
                    dic.Add(num, 1);
                }
            }
            int ans = 0;
            bool cannot = false;
            for(int j=0; j<100; j++) {
                if(dic.Count < 3) {
                    cannot = true;
                    break;
                } else {
                    List<KeyValuePair<long, int>> subList = dic.OrderBy(a=> a.Value).ToList();
                    subList.Reverse();
                    for(int k=0; k<3; k++) {
                        dic[subList[k].Key]--;
                        if(dic[subList[k].Key] <= 0) {
                            dic.Remove(subList[k].Key);   
                        }
                    }
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }



    }
 
 
 
    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"




4
8
2 2 5 8 7 3 8 8
3
1 1 1
6
1 1 2 2 2 3
15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15




 
";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        public static int[] GetInt(char delimiter = ' ', bool trim = false)
        {
            string inptStr = ReadLine();
            if (trim)
            {
                inptStr = inptStr.Trim();
            }
            string[] inpt = inptStr.Split(delimiter);
            int[] ret = new int[inpt.Length];
            for (int i = 0; i < inpt.Length; i++)
            {
                ret[i] = int.Parse(inpt[i]);
            }
            return ret;
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0