Submission #453999
Source Code Expand
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; /* 問題文 雨の降っていた時刻というのは、降水量と並んで重要です。今、ある 1 日の、雨が降っていた時刻に関するメモが見つかったので、これを整理して、雨の降っていた時刻を調べたいと思います。 整理は、以下の規則に従って行います。 感雨時間のメモから、その日 1 日の雨の降っていた時刻を時系列順に出す。日付を超えて降っている雨は、 00:00 降り始めや 24:00 降り終わりとして扱われるものとし、日付をまたぐようなメモは入力されない。 雨の降り始め・降り終わりはそれぞれ直前・直後の 5 分単位の時刻に丸める。例えば、13:23 に降り始めて 14:01 にやんだ雨は、13:20 から 14:05 まで降っていたということにする。 丸めた後の結果において、2 つ以上のメモに書かれていた感雨時刻が重複した場合、1 つの連続した雨とみなす。例えば、11:06 に降り始めて 11:23 にやんだ雨、11:29 に降り始めて 12:03 にやんだ雨、11:48 に降り始めて 12:10 にやんだ雨の 3 つがあった場合、11:05〜11:25、11:25〜12:05、11:45〜12:10 の 3 つの雨であるが、時間がかぶっているところをくっつけて 11:05 から 12:10 まで降っていた、1 つの連続した雨ということにする。 メモの内容が入力される時、雨の降っていた時刻を、この規則に合致するよう整理して出力するプログラムを作成してください。 入力 入力は以下の形式で標準入力から与えられる。 N S1-E1 S2-E2 : SN-EN 1 行目には、連続して雨の降っていた時刻の数を表す整数 N (1≦N≦30,000) が与えられる。 2 行目から N+1 行目までの N 行で、雨の降り始めの時刻と降り終わりの時刻が与えられる。 この中の i (1≦i≦N) 行目において、雨が降り始めた時刻 Si と雨が降り終わった時刻 Ei がハイフンで区切られて与えられる。 時刻 Si と Ei において 時刻は必ず 4 桁の非負整数で与えられる。 時刻の上 2 桁が時間 (hour) 、下 2 桁が分 (minute) を表す。 時刻は 0000 から 2400 まで取り得る。ただし下 2 桁の部分が 59 を超えることはない。 Si が Ei より前の時刻であることが保証されている。 出力 雨が降っていた時刻を整理して、降り始めの時刻の早い順番に、降り始めた時刻と降り終わりの時刻をハイフンで区切って出力せよ。 その際、連続した 1 つの雨を 1 行に出力し、時刻の形式は入力と同じ形式を用いること。 また、出力の末尾には改行を入れること。 入力例 1 4 1148-1210 1323-1401 1106-1123 1129-1203 11:48〜12:10 の間、雨が降っていた。 13:23〜14:01 の間、雨が降っていた。 11:06〜11:23 の間、雨が降っていた。 11:29〜12:03 の間、雨が降っていた。 出力例 1 1105-1210 1320-1405 入力を 5 分単位に丸めると、順に 1145-1210、1320-1405、1105-1125、1125-1205となる。 これを降り始めの時刻の早い順に直すと、1105-1125、1125-1205、1145-1210、1320-1405となる。 1105-1125、1125-1205の 2 つは、前者の降り終わりの時刻と後者の降り始めの時刻が一致するので、くっついて 1105-1205 となる。 さらに、1105-1205 と、1145-1210 は、後者の降り始めの時刻が前者の降っている時刻の間に入るので、くっついて 1105-1210 となる。 そのため、結局この例のような出力となる。 なお、出力は雨の降った時刻の早い順でなければならない。 入力例 2 1 0000-2400 出力例 2 0000-2400 一日中雨が降っている場合である。 入力例 3 6 1157-1306 1159-1307 1158-1259 1230-1240 1157-1306 1315-1317 全く同じメモが複数存在する場合もある。 出力例 3 1155-1310 1315-1320 */ namespace TEST { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine());//提出用 /*int N = 6;//デバッグ用 string[] test ={//デバッグ用1ここから "1157-1306", "1159-1307", "1158-1259", "1230-1240", "1157-1306", "1315-1317" };*///ここまで string[]line=new string[2]; int[] begin=new int[N], end = new int[N]; int hour=0, min=0; int a, count = 0, c = 0 ; int[] raintime = new int[1447]; int time; bool start=false; for (int i = 0; i < N; i++)//入力、入力データを5分毎に変換、24時間を1440分に換算 { line = Console.ReadLine().Split('-');//提出用 // line = test[i].Split('-');//デバッグ用1 begin[i] = int.Parse(line[0]); end[i] = int.Parse(line[1]); hour = begin[i] / 100; min = begin[i] % 100; min = min - min % 5; begin[i] = hour*100+min; begin[i] = begin[i] / 100 * 60+ min; //Console.WriteLine("{0}", hour+min);//時間出力デバッグ用2 hour = end[i] / 100; min = end[i] % 100; a = 5-min % 5; if (a != 5) min = min + a; if(min==60) { hour ++; min = 0; } end[i] = hour * 100 + min; end[i] = end[i] / 100 * 60 + min; //Console.WriteLine("{0}", hour+min);//時間出力デバッグ用2 } for (int i = 0; i <= 1440; i++)//振った時間は0以上にする。 { for (int j = 0; j < N; j++) { if (begin[j] <= i && i < end[j]) { raintime[i]++; } } /* //振った時間塗りつぶしデバッグ用3 Console.Write(raintime[i]); count++; if (count == 12) { Console.WriteLine(); count = 0; } */ } hour = 0; min = 0; for (int i = 0; i <= 1445; i++)//60分毎に+100するカウントを作って時計を作る { min = i - hour * 60; if(min==60) { hour++; min = 0; } time = hour * 100 + min; /* Console.Write(time+" ");//デバッグ用時計 count++; if (count == 60) { Console.WriteLine(); count = 0; }*/ if (raintime[i]>0&&!start) { start=true; c = 0; if (time < 10) Console.Write("000"+time+"-"); else if (time < 100) Console.Write("00" + time + "-"); else if (time < 1000) Console.Write("0" + time + "-"); else Console.Write(time + "-"); } else if(raintime[i]==0) { c++; if(c==5&&start) { start = false; Console.WriteLine(time-4); c = 0; } } } //Console.ReadKey(); } } }
Submission Info
Submission Time | |
---|---|
Task | D - 感雨時刻の整理 |
User | vaiozx |
Language | C# (Mono 2.10.8.1) |
Score | 0 |
Code Size | 9059 Byte |
Status | WA |
Exec Time | 485 ms |
Memory | 8472 KB |
Judge Result
Set Name | all | ||||
---|---|---|---|---|---|
Score / Max Score | 0 / 100 | ||||
Status |
|
Set Name | Test Cases |
---|---|
all | 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 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_01.txt | AC | 154 ms | 7964 KB |
00_sample_02.txt | AC | 131 ms | 7880 KB |
00_sample_03.txt | AC | 134 ms | 7916 KB |
cho_cho_chokudai.txt | AC | 343 ms | 8400 KB |
chokudai_ga_cho.txt | AC | 319 ms | 8452 KB |
test_01.txt | WA | 133 ms | 7960 KB |
test_02.txt | WA | 132 ms | 7964 KB |
test_03.txt | WA | 134 ms | 7964 KB |
test_04.txt | WA | 132 ms | 7940 KB |
test_05.txt | WA | 133 ms | 7972 KB |
test_06.txt | AC | 134 ms | 7948 KB |
test_07.txt | AC | 132 ms | 7932 KB |
test_08.txt | AC | 132 ms | 7940 KB |
test_09.txt | AC | 135 ms | 8008 KB |
test_10.txt | AC | 136 ms | 8016 KB |
test_11.txt | WA | 134 ms | 8060 KB |
test_12.txt | AC | 134 ms | 7960 KB |
test_13.txt | AC | 134 ms | 7944 KB |
test_14.txt | AC | 138 ms | 8136 KB |
test_15.txt | AC | 137 ms | 8060 KB |
test_16.txt | WA | 133 ms | 7940 KB |
test_17.txt | AC | 135 ms | 8136 KB |
test_18.txt | AC | 132 ms | 7944 KB |
test_19.txt | AC | 133 ms | 8004 KB |
test_20.txt | AC | 136 ms | 7992 KB |
test_21.txt | AC | 467 ms | 8412 KB |
test_22.txt | AC | 465 ms | 8352 KB |
test_23.txt | AC | 473 ms | 8444 KB |
test_24.txt | AC | 475 ms | 8364 KB |
test_25.txt | AC | 485 ms | 8472 KB |
test_26.txt | AC | 451 ms | 8444 KB |
test_27.txt | WA | 276 ms | 8444 KB |
test_28.txt | WA | 431 ms | 8416 KB |
test_29.txt | AC | 130 ms | 7836 KB |
test_30.txt | WA | 136 ms | 7928 KB |
test_31.txt | WA | 178 ms | 8088 KB |
test_32.txt | WA | 130 ms | 7952 KB |
test_33.txt | WA | 353 ms | 8448 KB |
test_34.txt | WA | 132 ms | 7972 KB |
test_35.txt | WA | 136 ms | 7932 KB |
test_36.txt | AC | 460 ms | 8408 KB |
test_37.txt | WA | 457 ms | 8416 KB |
test_38.txt | AC | 452 ms | 8396 KB |
test_39.txt | WA | 420 ms | 8436 KB |
test_40.txt | WA | 452 ms | 8412 KB |
test_41.txt | AC | 295 ms | 8320 KB |
test_42.txt | AC | 466 ms | 8416 KB |
test_43.txt | AC | 319 ms | 8392 KB |