結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  14番 | 
| 提出日時 | 2016-04-17 05:26:07 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 227 ms / 5,000 ms | 
| コード長 | 2,675 bytes | 
| コンパイル時間 | 995 ms | 
| コンパイル使用メモリ | 109,184 KB | 
| 実行使用メモリ | 23,552 KB | 
| 最終ジャッジ日時 | 2024-10-04 10:23:55 | 
| 合計ジャッジ時間 | 2,188 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
コンパイルメッセージ
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.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();
    }
}
            
            
            
        