AtCoder Beginner Contest 001

Submission #380725

Source codeソースコード

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;

namespace AtCoderWorkspace
{
	public class Program
	{
		public static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var memos = Enumerable.Repeat(0, n).Select(_ => FixMemo(ReadMemo()))
				.OrderBy(i => i.Item1)
				.ThenBy(i => i.Item2)
				.ToArray();

			for (int i = 1; i < memos.Length; ++i)
			{
				var m1 = memos[i - 1];
				var m2 = memos[i];
				if (m1.Item2 >= m2.Item1)
				{
					memos[i] = Tuple.Create(Min(m1.Item1, m2.Item1), Max(m1.Item2, m2.Item2));
					memos[i - 1] = null;
				}
			}
			foreach (var memo in memos)
				if (memo != null)
					Console.WriteLine("{0}-{1}", ToDisplay(memo.Item1), ToDisplay(memo.Item2));
		}
		static TimeSpan Min(TimeSpan l, TimeSpan r)
		{
			if (l < r)
				return l;
			else
				return r;
		}
		static TimeSpan Max(TimeSpan l, TimeSpan r)
		{
			if (l < r)
				return r;
			else
				return l;
		}
		static Tuple<TimeSpan, TimeSpan> ReadMemo()
		{
			var r = Console.ReadLine().Split('-');
			return Tuple.Create(ToTimeSapn(r[0]), ToTimeSapn(r[1]));
		}
		static TimeSpan ToTimeSapn(string input)
		{
			var m = Regex.Match(input, "^([0-9]{2})([0-9]{2})$");
			return new TimeSpan(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value), 0);
		}

		static Tuple<TimeSpan, TimeSpan> FixMemo(Tuple<TimeSpan, TimeSpan> value)
		{
			return Tuple.Create(
				TimeSpan.FromMinutes(Math.Floor(value.Item1.TotalMinutes / 5) * 5),
				TimeSpan.FromMinutes(Math.Ceiling(value.Item2.TotalMinutes / 5) * 5));
		}
		static string ToDisplay(TimeSpan value)
		{
			return string.Format("{0:00}{1:00}", (int)value.TotalHours, value.Minutes);
		}
	}
}

Submission

Task問題 D - 感雨時刻の整理
User nameユーザ名 frozenlib
Created time投稿日時
Language言語 C# (Mono 2.10.8.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 1821 Byte
File nameファイル名
Exec time実行時間 619 ms
Memory usageメモリ使用量 15144 KB

Test case

Set

Set name Score得点 / Max score Cases
all 100 / 100 00_sample_01.txt,00_sample_02.txt,00_sample_03.txt,cho_cho_chokudai.txt,chokudai_ga_cho.txt,test_01.txt,test_02.txt,test_03.txt,test_04.txt,test_05.txt,test_06.txt,test_07.txt,test_08.txt,test_09.txt,test_10.txt,test_11.txt,test_12.txt,test_13.txt,test_14.txt,test_15.txt,test_16.txt,test_17.txt,test_18.txt,test_19.txt,test_20.txt,test_21.txt,test_22.txt,test_23.txt,test_24.txt,test_25.txt,test_26.txt,test_27.txt,test_28.txt,test_29.txt,test_30.txt,test_31.txt,test_32.txt,test_33.txt,test_34.txt,test_35.txt,test_36.txt,test_37.txt,test_38.txt,test_39.txt,test_40.txt,test_41.txt,test_42.txt,test_43.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_sample_01.txt AC 223 ms 11716 KB
00_sample_02.txt AC 216 ms 11752 KB
00_sample_03.txt AC 217 ms 11724 KB
cho_cho_chokudai.txt AC 575 ms 14896 KB
chokudai_ga_cho.txt AC 575 ms 14896 KB
test_01.txt AC 241 ms 11792 KB
test_02.txt AC 270 ms 11804 KB
test_03.txt AC 258 ms 11800 KB
test_04.txt AC 285 ms 11824 KB
test_05.txt AC 255 ms 11832 KB
test_06.txt AC 225 ms 11724 KB
test_07.txt AC 221 ms 11724 KB
test_08.txt AC 226 ms 11724 KB
test_09.txt AC 226 ms 11848 KB
test_10.txt AC 232 ms 11840 KB
test_11.txt AC 234 ms 11824 KB
test_12.txt AC 227 ms 11744 KB
test_13.txt AC 227 ms 11796 KB
test_14.txt AC 227 ms 11752 KB
test_15.txt AC 229 ms 11868 KB
test_16.txt AC 221 ms 11792 KB
test_17.txt AC 226 ms 11788 KB
test_18.txt AC 222 ms 11748 KB
test_19.txt AC 224 ms 11820 KB
test_20.txt AC 224 ms 11840 KB
test_21.txt AC 577 ms 14928 KB
test_22.txt AC 571 ms 14908 KB
test_23.txt AC 578 ms 15116 KB
test_24.txt AC 574 ms 14888 KB
test_25.txt AC 574 ms 14892 KB
test_26.txt AC 584 ms 14908 KB
test_27.txt AC 611 ms 15060 KB
test_28.txt AC 593 ms 14884 KB
test_29.txt AC 224 ms 11604 KB
test_30.txt AC 227 ms 11724 KB
test_31.txt AC 285 ms 12344 KB
test_32.txt AC 224 ms 11720 KB
test_33.txt AC 464 ms 14376 KB
test_34.txt AC 217 ms 11724 KB
test_35.txt AC 229 ms 11748 KB
test_36.txt AC 577 ms 14892 KB
test_37.txt AC 578 ms 15028 KB
test_38.txt AC 579 ms 14852 KB
test_39.txt AC 583 ms 15144 KB
test_40.txt AC 583 ms 14936 KB
test_41.txt AC 592 ms 14900 KB
test_42.txt AC 619 ms 14900 KB
test_43.txt AC 601 ms 15084 KB