Submission #145481


Source Code Expand

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
	public static void main(String[] args) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		
		int n = sc.nextInt();
		List<Integer[]> rainTimes = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			String[] tmp = sc.next().split("-");
			int s = start(tmp[0]);
			int e = end(tmp[1]);
			
			Integer[] t = {s, e};
			rainTimes.add(t);
		}
		sc.close();
		
		// マージ
		boolean[] day = new boolean[24 * 60 / 5 + 1];
		Arrays.fill(day, false);
		for (Integer[] rain : rainTimes) {
			int start = rain[0] / 5;
			int end = rain[1] / 5;
			Arrays.fill(day, start, end, true);
		}
		
		// 出力
		List<String> out = new ArrayList<>();
		StringBuilder temp = new StringBuilder(9);
		boolean flag = false;
		for (int i = 0; i < day.length; i++) {
			boolean t = day[i];
			
			if (!t && !flag) continue;
			
			// end
			if (!t && flag) {
				int h = i * 5 / 60;
				int m = i * 5 % 60;
				temp.append(String.format("%02d", h));
				temp.append(String.format("%02d", m));
				out.add(temp.toString());
				temp = new StringBuilder(9);
				flag = false;
			}
			// start
			else if (t && !flag) {
				int h = i * 5 / 60;
				int m = i * 5 % 60;
				temp.append(String.format("%02d", h));
				temp.append(String.format("%02d", m));
				temp.append("-");
				flag = true;
			}
		}
		if (flag) {
			temp.append("2400");
			out.add(temp.toString());
		}
		for (String string : out) {
			System.out.println(string);
		}
	}
	
	static int start(String s) {
		int min = Integer.parseInt(s.substring(0, 2)) * 60;
		min += Integer.parseInt(s.substring(2));
		min -= min % 5;
		return min;
	}
	
	static int end(String s) {
		int min = Integer.parseInt(s.substring(0, 2)) * 60;
		min += Integer.parseInt(s.substring(2));
		if (min % 5 > 0) {
			min += 5 - min % 5;
		}
		return min;
	}
}

Submission Info

Submission Time
Task D - 感雨時刻の整理
User k3suk3
Language Java (OpenJDK 1.7.0)
Score 100
Code Size 1968 Byte
Status AC
Exec Time 1038 ms
Memory 41424 KB

Judge Result

Set Name all
Score / Max Score 100 / 100
Status
AC × 48
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 536 ms 23596 KB
00_sample_02.txt AC 479 ms 23608 KB
00_sample_03.txt AC 475 ms 23640 KB
cho_cho_chokudai.txt AC 985 ms 40772 KB
chokudai_ga_cho.txt AC 970 ms 41392 KB
test_01.txt AC 534 ms 24512 KB
test_02.txt AC 542 ms 24508 KB
test_03.txt AC 535 ms 24500 KB
test_04.txt AC 551 ms 24544 KB
test_05.txt AC 579 ms 24376 KB
test_06.txt AC 526 ms 24120 KB
test_07.txt AC 512 ms 23740 KB
test_08.txt AC 492 ms 23732 KB
test_09.txt AC 552 ms 25564 KB
test_10.txt AC 536 ms 25052 KB
test_11.txt AC 548 ms 24928 KB
test_12.txt AC 553 ms 24504 KB
test_13.txt AC 504 ms 23864 KB
test_14.txt AC 547 ms 25676 KB
test_15.txt AC 550 ms 25016 KB
test_16.txt AC 487 ms 23844 KB
test_17.txt AC 546 ms 24868 KB
test_18.txt AC 603 ms 23860 KB
test_19.txt AC 544 ms 24804 KB
test_20.txt AC 535 ms 24756 KB
test_21.txt AC 1031 ms 41192 KB
test_22.txt AC 1018 ms 40844 KB
test_23.txt AC 975 ms 41256 KB
test_24.txt AC 965 ms 41424 KB
test_25.txt AC 951 ms 40608 KB
test_26.txt AC 1034 ms 41100 KB
test_27.txt AC 1038 ms 40804 KB
test_28.txt AC 996 ms 41404 KB
test_29.txt AC 469 ms 23484 KB
test_30.txt AC 477 ms 23740 KB
test_31.txt AC 702 ms 29652 KB
test_32.txt AC 476 ms 23564 KB
test_33.txt AC 987 ms 41384 KB
test_34.txt AC 471 ms 23484 KB
test_35.txt AC 507 ms 24628 KB
test_36.txt AC 945 ms 40612 KB
test_37.txt AC 1007 ms 40104 KB
test_38.txt AC 956 ms 40580 KB
test_39.txt AC 974 ms 40804 KB
test_40.txt AC 981 ms 39952 KB
test_41.txt AC 954 ms 40396 KB
test_42.txt AC 954 ms 40056 KB
test_43.txt AC 1037 ms 40264 KB