Submission #616213


Source Code Expand

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Map.Entry;
import java.util.TreeMap;

public class Main {
	InputStream is;

	int __t__ = 1;
	int __f__ = 0;
	int __FILE_DEBUG_FLAG__ = __f__;
	String __DEBUG_FILE_NAME__ = "src/D2";

	FastScanner in;
	PrintWriter out;
	
	class State implements Comparable<State> {
		int id;
		int v;

		State(int id, int v) {
			this.id = id;
			this.v = v;
		}

		public int compareTo(State s) {
			return v - s.v;
		}

		public String dump(String symbol) {
			return symbol + " : " + id + " " + v;
		}
	}
	
	void solve() {
		int n = in.nextInt() - 1;
		int[] a = in.nextIntArray(n);
		
		State[] st = new State[n];
		for (int i = 0; i < n; i++) {
			st[i] = new State(i, a[i]);
		}
		Arrays.sort(st);
		
		int[] res = new int[n+1];
		Arrays.fill(res, Integer.MAX_VALUE);
		for (int i = 0; i < n; i++) {
			res[st[i].id] = Math.min(res[st[i].id], st[i].v);
			res[st[i].id+1] = Math.min(res[st[i].id+1], st[i].v);			
		}
		for (int i = 0; i < n + 1; i++) {
			out.print(res[i] + " ");
		}
		out.println();
		out.close();
	}
	
	public void run() {
		if (__FILE_DEBUG_FLAG__ == __t__) {
			try {
				is = new FileInputStream(__DEBUG_FILE_NAME__);
			} catch (FileNotFoundException e) {
				// TODO 自動生成された catch ブロック
				e.printStackTrace();
			}
			System.out.println("FILE_INPUT!");
		} else {
			is = System.in;
		}
		in = new FastScanner(is);
		out = new PrintWriter(System.out);

		solve();
	}
	
	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 Info

Submission Time
Task B - 積み鉛筆
User hiro116s
Language Java (OpenJDK 1.7.0)
Score 80
Code Size 4904 Byte
Status AC
Exec Time 943 ms
Memory 39404 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 80 / 80
Status
AC × 3
AC × 15
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All subtask0_0.txt, subtask0_1.txt, subtask0_10.txt, subtask0_11.txt, subtask0_12.txt, subtask0_13.txt, subtask0_14.txt, subtask0_2.txt, subtask0_3.txt, subtask0_4.txt, subtask0_5.txt, subtask0_6.txt, subtask0_7.txt, subtask0_8.txt, subtask0_9.txt
Case Name Status Exec Time Memory
sample1.txt AC 351 ms 22260 KB
sample2.txt AC 354 ms 22248 KB
sample3.txt AC 362 ms 22196 KB
subtask0_0.txt AC 943 ms 38636 KB
subtask0_1.txt AC 611 ms 35484 KB
subtask0_10.txt AC 669 ms 36508 KB
subtask0_11.txt AC 671 ms 34760 KB
subtask0_12.txt AC 939 ms 38688 KB
subtask0_13.txt AC 608 ms 35424 KB
subtask0_14.txt AC 664 ms 34656 KB
subtask0_2.txt AC 675 ms 35692 KB
subtask0_3.txt AC 892 ms 39404 KB
subtask0_4.txt AC 618 ms 35868 KB
subtask0_5.txt AC 658 ms 33248 KB
subtask0_6.txt AC 882 ms 38784 KB
subtask0_7.txt AC 631 ms 33420 KB
subtask0_8.txt AC 661 ms 35560 KB
subtask0_9.txt AC 937 ms 37436 KB