結果

問題 No.318 学学学学学
ユーザー tentententen
提出日時 2021-11-11 13:09:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 990 ms / 2,000 ms
コード長 2,032 bytes
コンパイル時間 2,563 ms
コンパイル使用メモリ 80,800 KB
実行使用メモリ 82,812 KB
最終ジャッジ日時 2024-05-02 06:23:23
合計ジャッジ時間 17,702 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 198 ms
55,044 KB
testcase_01 AC 313 ms
59,160 KB
testcase_02 AC 353 ms
59,136 KB
testcase_03 AC 263 ms
57,960 KB
testcase_04 AC 320 ms
58,680 KB
testcase_05 AC 863 ms
82,812 KB
testcase_06 AC 692 ms
73,976 KB
testcase_07 AC 673 ms
71,484 KB
testcase_08 AC 612 ms
68,612 KB
testcase_09 AC 569 ms
65,564 KB
testcase_10 AC 517 ms
64,964 KB
testcase_11 AC 990 ms
81,016 KB
testcase_12 AC 748 ms
74,652 KB
testcase_13 AC 713 ms
72,716 KB
testcase_14 AC 677 ms
72,444 KB
testcase_15 AC 582 ms
65,520 KB
testcase_16 AC 497 ms
64,852 KB
testcase_17 AC 537 ms
74,204 KB
testcase_18 AC 554 ms
74,504 KB
testcase_19 AC 567 ms
76,924 KB
testcase_20 AC 444 ms
64,240 KB
testcase_21 AC 55 ms
50,124 KB
testcase_22 AC 55 ms
50,324 KB
testcase_23 AC 55 ms
50,436 KB
testcase_24 AC 58 ms
50,400 KB
testcase_25 AC 57 ms
50,280 KB
testcase_26 AC 56 ms
50,420 KB
testcase_27 AC 54 ms
50,144 KB
testcase_28 AC 56 ms
50,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        TreeMap<Integer, ArrayList<Integer>> pattern = new TreeMap<>();
        int[] values = new int[n];
        TreeSet<Integer> remain = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
            if (!pattern.containsKey(-values[i])) {
                pattern.put(-values[i], new ArrayList<>());
            }
            pattern.get(-values[i]).add(i);
            remain.add(i);
        }
        for (int x : pattern.keySet()) {
            ArrayList<Integer> list = pattern.get(x);
            Integer key = list.get(0) - 1;
            while ((key = remain.higher(key)) != null) {
                if (key > list.get(list.size() - 1)) {
                    break;
                }
                values[key] = -x;
                remain.remove(key);
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            if (i > 0) {
                sb.append(" ");
            }
            sb.append(values[i]);
        }
        System.out.println(sb);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0