結果
問題 | No.59 鉄道の旅 |
ユーザー |
![]() |
提出日時 | 2016-04-07 03:11:09 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 532 ms / 5,000 ms |
コード長 | 2,745 bytes |
コンパイル時間 | 2,817 ms |
コンパイル使用メモリ | 105,984 KB |
実行使用メモリ | 22,272 KB |
最終ジャッジ日時 | 2024-12-24 22:16:52 |
合計ジャッジ時間 | 3,331 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 |
コンパイルメッセージ
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;public class Program{public void Proc(){Reader.IsDebug = false;int[] inpt = Reader.GetInt(' ', true);int stationCount = inpt[0];int nimptsuMax = inpt[1];List<int> itemList = new List<int>();for(int i=0; i<stationCount; i++) {int newNimotsu = int.Parse(Reader.ReadLine());int idx = 0;if(itemList.Count > 0) {idx = GetIndex(itemList, Math.Abs(newNimotsu), 0, itemList.Count - 1);}if(newNimotsu > 0) {if(itemList.Count - idx >= nimptsuMax) {// 荷物つまない} else{itemList.Insert(idx, newNimotsu);}} else{if(idx < itemList.Count && itemList[idx] == Math.Abs(newNimotsu)) {itemList.RemoveAt(idx);}}}int ans = itemList.Count;Console.WriteLine(ans);}private int GetIndex(List<int> target, int item, int minIdx, int maxIdx) {if(target[minIdx] >= item) {return minIdx;}if(target[maxIdx] < item) {return maxIdx + 1;}int mid = (minIdx + maxIdx) / 2;if(mid == minIdx) {return maxIdx;}if(target[mid] >= item) {return GetIndex(target, item, minIdx, mid);} else{return GetIndex(target, item, mid, maxIdx);}}public static void Main(string[] args){Program prg = new Program();prg.Proc();}}class Reader{public static bool IsDebug = true;private static System.IO.StringReader sr;public static string ReadLine() {if(IsDebug) {if(sr == null) {sr = new System.IO.StringReader(initStr.Trim());}return sr.ReadLine();} else {return Console.ReadLine();}}public static int[] GetInt(char delimiter = ' ', bool mustTrim = false) {string src = ReadLine();if(mustTrim) {src = src.Trim();}string[] inpt = src.Split(delimiter);int[] ret = new int[inpt.Length];for(int i=0; i<inpt.Length; i++) {string item = inpt[i];if(mustTrim) {item = item.Trim();}ret[i] = int.Parse(item);}return ret;}private static string initStr = @"";}