結果
問題 | No.318 学学学学学 |
ユーザー | Grenache |
提出日時 | 2015-12-11 01:02:18 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 822 ms / 2,000 ms |
コード長 | 3,304 bytes |
コンパイル時間 | 4,804 ms |
コンパイル使用メモリ | 76,756 KB |
実行使用メモリ | 76,448 KB |
最終ジャッジ日時 | 2023-10-13 10:44:54 |
合計ジャッジ時間 | 17,493 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 168 ms
55,224 KB |
testcase_01 | AC | 243 ms
59,292 KB |
testcase_02 | AC | 263 ms
59,436 KB |
testcase_03 | AC | 227 ms
61,132 KB |
testcase_04 | AC | 243 ms
59,120 KB |
testcase_05 | AC | 690 ms
76,304 KB |
testcase_06 | AC | 822 ms
70,840 KB |
testcase_07 | AC | 755 ms
70,376 KB |
testcase_08 | AC | 675 ms
69,036 KB |
testcase_09 | AC | 491 ms
65,360 KB |
testcase_10 | AC | 380 ms
65,256 KB |
testcase_11 | AC | 691 ms
76,448 KB |
testcase_12 | AC | 563 ms
72,076 KB |
testcase_13 | AC | 496 ms
67,676 KB |
testcase_14 | AC | 462 ms
68,416 KB |
testcase_15 | AC | 399 ms
66,064 KB |
testcase_16 | AC | 370 ms
64,848 KB |
testcase_17 | AC | 632 ms
70,568 KB |
testcase_18 | AC | 435 ms
69,656 KB |
testcase_19 | AC | 625 ms
70,544 KB |
testcase_20 | AC | 345 ms
62,952 KB |
testcase_21 | AC | 47 ms
50,096 KB |
testcase_22 | AC | 47 ms
49,952 KB |
testcase_23 | AC | 47 ms
49,636 KB |
testcase_24 | AC | 47 ms
49,752 KB |
testcase_25 | AC | 46 ms
49,796 KB |
testcase_26 | AC | 47 ms
49,908 KB |
testcase_27 | AC | 47 ms
50,228 KB |
testcase_28 | AC | 47 ms
49,780 KB |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.Map; public class Main_yukicoder318 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int n = sc.nextInt(); int[] a = new int[n]; Map<Integer, Range> hm = new HashMap<Integer, Range>(); for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); if (hm.containsKey(a[i])) { Range r = hm.get(a[i]); if (r.e < i) { r.e = i; } } else { hm.put(a[i], new Range(a[i], i, i)); } } LinkedList<Range> list = new LinkedList<Range>(hm.values()); Collections.sort(list, Collections.reverseOrder()); // Deque<Range> st = new ArrayDeque<Range>(); int[] b = new int[n]; // for (int i = 0; i < n; i++) { // while (list.peekFirst().s == i) { // if (!st.isEmpty() && st.peek().t > list.peekFirst().t) { // list.removeFirst(); // continue; // } // st.push(list.removeFirst()); // } // // while (!st.isEmpty() && st.peek().e < i) { // st.pop(); // } for (Range e : list) { Arrays.fill(b, e.s, e.e + 1, e.t); } for (int i = 0; i < n; i++) { if (i != 0) { pr.print(" "); } pr.print(b[i]); } pr.println(); pr.close(); sc.close(); } private static class Range implements Comparable<Range> { int t; int s; int e; Range(int t, int s, int e) { this.t = t; this.s = s; this.e = e; } @Override public int compareTo(Range o) { // if (this.s != o.s) { // return Integer.compare(this.s, o.s); // } // if (this.e != o.e) { // return Integer.compare(o.e, this.e); // } if (this.t != o.t) { return Integer.compare(o.t, this.t); } return 0; } } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }