結果

問題 No.241 出席番号(1)
ユーザー 14番
提出日時 2016-05-08 22:58:49
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 3,310 bytes
コンパイル時間 2,125 ms
コンパイル使用メモリ 109,440 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-11-30 21:36:01
合計ジャッジ時間 4,280 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
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();
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0