結果

問題 No.241 出席番号(1)
ユーザー 14番14番
提出日時 2016-05-08 22:58:49
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 3,310 bytes
コンパイル時間 2,711 ms
コンパイル使用メモリ 107,896 KB
実行使用メモリ 24,012 KB
最終ジャッジ日時 2023-08-20 17:55:00
合計ジャッジ時間 6,683 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
24,000 KB
testcase_01 AC 70 ms
21,888 KB
testcase_02 AC 72 ms
21,872 KB
testcase_03 AC 62 ms
19,796 KB
testcase_04 AC 72 ms
21,788 KB
testcase_05 AC 62 ms
21,704 KB
testcase_06 AC 63 ms
21,716 KB
testcase_07 AC 62 ms
21,700 KB
testcase_08 AC 63 ms
21,732 KB
testcase_09 AC 71 ms
21,824 KB
testcase_10 AC 71 ms
21,888 KB
testcase_11 AC 72 ms
21,884 KB
testcase_12 AC 72 ms
23,940 KB
testcase_13 AC 72 ms
23,876 KB
testcase_14 AC 73 ms
19,860 KB
testcase_15 AC 72 ms
21,784 KB
testcase_16 AC 67 ms
19,700 KB
testcase_17 AC 63 ms
21,696 KB
testcase_18 AC 72 ms
24,012 KB
testcase_19 AC 71 ms
19,840 KB
testcase_20 AC 72 ms
23,852 KB
testcase_21 AC 72 ms
21,840 KB
testcase_22 AC 71 ms
19,856 KB
testcase_23 AC 72 ms
23,844 KB
testcase_24 AC 72 ms
21,776 KB
testcase_25 AC 70 ms
21,916 KB
testcase_26 AC 72 ms
21,848 KB
testcase_27 AC 69 ms
21,816 KB
testcase_28 AC 72 ms
23,840 KB
testcase_29 AC 73 ms
21,824 KB
testcase_30 AC 72 ms
22,008 KB
testcase_31 AC 72 ms
19,776 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.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int seitoCount = int.Parse(Reader.ReadLine());
        Dictionary<int, int> kirawareDic = new Dictionary<int, int>();
        int[] ans = new int[seitoCount];
        for(int i=0; i<ans.Length; i++) {
            ans[i] = -1;
        }
        bool canProc = true;
        Dictionary<int, int> input = new Dictionary<int, int>();

        List<int> numList = new List<int>();
        for(int i=0; i<seitoCount; i++) {
            int num = int.Parse(Reader.ReadLine());
            input.Add(i, num);
            if(num < seitoCount) {
                if(kirawareDic.ContainsKey(num)) {
                    kirawareDic[num]++;
                } else
                {
                    kirawareDic.Add(num, 1);
                }
            }
            numList.Add(i);
        }
        kirawareDic.OrderByDescending(a=>a.Value).ToList().ForEach((a)=>{
            List<int> target = new List<int>(input.Where(b=>b.Value != a.Key && ans[b.Key] < 0).Select(c=>c.Key));
            target.Sort((b, c)=>{
                bool bFlag = numList.Contains(input[b]);
                bool cFlag = numList.Contains(input[c]);
                if(bFlag && (!cFlag)) {
                    return -1;
                }
                if((!bFlag) && cFlag) {
                    return 1;
                }
                return 0;
            });
            if(target.Count > 0) {
                ans[target[0]] = a.Key;
                numList.Remove(a.Key);
            } else
            {
                canProc = false;
            }
        });
        if(numList.Count > 0 && canProc) {
            numList.ForEach((a)=>{
                for(int i=0; i<ans.Length; i++) {
                    if(ans[i] < 0) {
                        ans[i] = a;
                        break;
                    }
                }
            });
        }
        if(canProc) {
            ans.ToList().ForEach(a=>Console.WriteLine(a));
        } else
        {
            Console.WriteLine(-1);
        }
    }
    

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


5
1
1
1
0
1


 
";
        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