AtCoder Beginner Contest 001

Submission #296311

Source codeソースコード

import java.io.*;
import java.util.*;

public class Main {
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);

	class Pair implements Comparable<Pair> {
		int from, to;

		Pair(int from, int to) {
			this.from = from;
			this.to = to;
		}

		public int compareTo(Pair s) {
			return from - s.from;
		}
	}
	
	String extend(int x) {
		String res = Integer.toString(x);
		while (res.length() < 4) res = "0" + res;
		
		return res;
	}
	
	public void run() {
		int n = in.nextInt();
		
		Pair[] times = new Pair[n];
		for (int i = 0; i < n; i++) {
			String[] next = in.next().split("-");
			
			int from = Integer.valueOf(next[0]);
			int to = Integer.valueOf(next[1]);
			from -= (from % 5); to += (5 - (to % 5)) % 5;
			if (to % 100 == 60) to += 40;
			times[i] = new Pair(from, to);
//			System.out.println(from + " " + to);
		}
		
		Arrays.sort(times);
		for (int i = 0; i < n; i++) {
			int from = times[i].from, to = times[i].to;
			for (int j = i + 1; j < n; j++) {
				if (times[j].from <= to) {
					to = Math.max(times[j].to, to);
				} else {
					break;
				}
				i = j;
			}
			System.out.println(extend(from) + "-" + extend(to));
		}
		
		out.close();
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}

		System.out.println("----------------------------");
		System.out.println();
	}

	public void debug(Object... obj) {
		System.out.println(Arrays.deepToString(obj));
	}

	class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
			//stream = new FileInputStream(new File("dec.in"));

		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();

			return array;
		}

		int[][] nextIntMap(int n, int m) {
			int[][] map = new int[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextIntArray(m);
			}
			return map;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();

			return array;
		}

		long[][] nextLongMap(int n, int m) {
			long[][] map = new long[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextLongArray(m);
			}
			return map;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();

			return array;
		}

		double[][] nextDoubleMap(int n, int m) {
			double[][] map = new double[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextDoubleArray(m);
			}
			return map;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}

Submission

Task問題 D - 感雨時刻の整理
User nameユーザ名 hiro116s
Created time投稿日時
Language言語 Java (OpenJDK 1.7.0)
Status状態 AC
Score得点 100
Source lengthソースコード長 4423 Byte
File nameファイル名
Exec time実行時間 727 ms
Memory usageメモリ使用量 33752 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 348 ms 17876 KB
00_sample_02.txt AC 342 ms 17968 KB
00_sample_03.txt AC 344 ms 17904 KB
cho_cho_chokudai.txt AC 594 ms 30940 KB
chokudai_ga_cho.txt AC 626 ms 30924 KB
test_01.txt AC 366 ms 18104 KB
test_02.txt AC 361 ms 17996 KB
test_03.txt AC 357 ms 18068 KB
test_04.txt AC 361 ms 18084 KB
test_05.txt AC 353 ms 18052 KB
test_06.txt AC 353 ms 18008 KB
test_07.txt AC 348 ms 17880 KB
test_08.txt AC 349 ms 17872 KB
test_09.txt AC 368 ms 19124 KB
test_10.txt AC 366 ms 19116 KB
test_11.txt AC 363 ms 18836 KB
test_12.txt AC 371 ms 18568 KB
test_13.txt AC 359 ms 17916 KB
test_14.txt AC 365 ms 18816 KB
test_15.txt AC 388 ms 18992 KB
test_16.txt AC 363 ms 17960 KB
test_17.txt AC 374 ms 18868 KB
test_18.txt AC 363 ms 17920 KB
test_19.txt AC 398 ms 18648 KB
test_20.txt AC 377 ms 18884 KB
test_21.txt AC 684 ms 32376 KB
test_22.txt AC 722 ms 33036 KB
test_23.txt AC 664 ms 32556 KB
test_24.txt AC 696 ms 32540 KB
test_25.txt AC 717 ms 33592 KB
test_26.txt AC 709 ms 31924 KB
test_27.txt AC 638 ms 32424 KB
test_28.txt AC 669 ms 33100 KB
test_29.txt AC 343 ms 17872 KB
test_30.txt AC 347 ms 17900 KB
test_31.txt AC 467 ms 22784 KB
test_32.txt AC 352 ms 18004 KB
test_33.txt AC 649 ms 30868 KB
test_34.txt AC 348 ms 17888 KB
test_35.txt AC 357 ms 17948 KB
test_36.txt AC 682 ms 32888 KB
test_37.txt AC 727 ms 32364 KB
test_38.txt AC 713 ms 33016 KB
test_39.txt AC 693 ms 33752 KB
test_40.txt AC 684 ms 32628 KB
test_41.txt AC 587 ms 31088 KB
test_42.txt AC 659 ms 32008 KB
test_43.txt AC 578 ms 30716 KB