結果

問題 No.318 学学学学学
ユーザー tentententen
提出日時 2021-01-21 08:50:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,422 ms / 2,000 ms
コード長 1,291 bytes
コンパイル時間 3,281 ms
コンパイル使用メモリ 78,220 KB
実行使用メモリ 94,348 KB
最終ジャッジ日時 2023-08-25 20:10:04
合計ジャッジ時間 24,732 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 355 ms
62,300 KB
testcase_01 AC 508 ms
63,784 KB
testcase_02 AC 553 ms
65,320 KB
testcase_03 AC 454 ms
63,072 KB
testcase_04 AC 504 ms
63,404 KB
testcase_05 AC 1,380 ms
94,348 KB
testcase_06 AC 1,122 ms
81,788 KB
testcase_07 AC 1,082 ms
79,484 KB
testcase_08 AC 1,008 ms
76,956 KB
testcase_09 AC 932 ms
71,524 KB
testcase_10 AC 866 ms
72,172 KB
testcase_11 AC 1,422 ms
93,736 KB
testcase_12 AC 1,175 ms
82,888 KB
testcase_13 AC 1,060 ms
80,356 KB
testcase_14 AC 990 ms
77,472 KB
testcase_15 AC 963 ms
70,676 KB
testcase_16 AC 895 ms
71,740 KB
testcase_17 AC 907 ms
82,036 KB
testcase_18 AC 893 ms
81,840 KB
testcase_19 AC 936 ms
80,308 KB
testcase_20 AC 798 ms
70,780 KB
testcase_21 AC 120 ms
53,936 KB
testcase_22 AC 118 ms
55,960 KB
testcase_23 AC 121 ms
55,720 KB
testcase_24 AC 119 ms
56,212 KB
testcase_25 AC 119 ms
56,176 KB
testcase_26 AC 120 ms
55,756 KB
testcase_27 AC 118 ms
55,764 KB
testcase_28 AC 119 ms
56,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		TreeMap<Integer, ArrayList<Integer>> positions = new TreeMap<>();
		TreeSet<Integer> idxes = new TreeSet<>();
		for (int i = 0; i < n; i++) {
		    int x = -sc.nextInt();
		    if (!positions.containsKey(x)) {
		        positions.put(x, new ArrayList<>());
		    }
		    positions.get(x).add(i);
		    idxes.add(i);
		}
		int[] ans = new int[n];
		for (int x : positions.keySet()) {
		    if (positions.get(x).size() == 0) {
		        int y = positions.get(x).get(0);
		        if (idxes.contains(y)) {
		            ans[y] = -x;
		            idxes.remove(y);
		        }
		    } else {
		        int left = positions.get(x).get(0);
		        int right = positions.get(x).get(positions.get(x).size() - 1);
		        Integer key = left - 1;
		        while ((key = idxes.higher(key)) != null) {
		            if (key > right) {
		                break;
		            }
		            ans[key] = -x;
		            idxes.remove(key);
		        }
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    if (i > 0) {
		        sb.append(" ");
		    }
		    sb.append(ans[i]);
		}
		System.out.println(sb);
	}
}
0