結果
問題 |
No.318 学学学学学
|
ユーザー |
![]() |
提出日時 | 2016-01-30 14:05:57 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,381 bytes |
コンパイル時間 | 2,583 ms |
コンパイル使用メモリ | 81,200 KB |
実行使用メモリ | 87,844 KB |
最終ジャッジ日時 | 2024-09-21 19:11:13 |
合計ジャッジ時間 | 33,931 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 11 WA * 15 |
ソースコード
import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.Scanner; import java.util.TreeSet; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int list[] = new int[N]; HashMap<Integer, ArrayList<Integer>> pathMap = new HashMap<>(); Comparator<Integer> comp = new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o2.compareTo(o1); } }; TreeSet<Integer> checkList = new TreeSet<Integer>(comp); for(int i=0; i<N; i++) { int a = scan.nextInt(); list[i] = a; ArrayList<Integer> array = pathMap.get(a); if( array == null) { array = new ArrayList<>(); array.add(i); pathMap.put(a, array); } else { array.add(i); pathMap.put(a, array); checkList.add(a); } } scan.close(); for(int t : checkList) { //System.out.println("t : " + t); ArrayList<Integer> array = pathMap.get(t); if(array == null) continue; if(array.size() >= 2) { int from = array.get(0); int to = array.get(array.size()-1); for(int i=from; i<=to; i++) { if(list[i] > t) break; list[i] = t; } } } for(int i=0; i<N; i++) { if(i==0) { System.out.print(list[i]); } else { System.out.print(" " + list[i]); } } } }