結果

問題 No.318 学学学学学
ユーザー jp_stejp_ste
提出日時 2016-01-30 09:47:16
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,191 bytes
コンパイル時間 2,489 ms
コンパイル使用メモリ 83,516 KB
実行使用メモリ 72,352 KB
最終ジャッジ日時 2023-10-21 17:49:56
合計ジャッジ時間 10,401 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

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<>();
		int max = 0;
		int min = Integer.MAX_VALUE;
		
		for(int i=0; i<N; i++) {
			int a = scan.nextInt();
			list[i] = a;
			max = Math.max(max, a);
			min = Math.min(min, 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);
			}
		}
		
		for(int t=min; t<=max; t++) {
			ArrayList<Integer> array = pathMap.get(t);
			if(array == null) continue;
			
			if(array.size() == 1) {
				int index = array.get(0);
				list[index] = t;
				
			} else if(array.size() == 2) {
				int from = array.get(0);
				int to = array.get(1);
				for(int i=from; i<=to; i++) {
					list[i] = t;
				}
			}
		}
		
		for(int i=0; i<N; i++) {
			if(i==0) {
				System.out.print(list[i]);
			} else {
				System.out.print(" " + list[i]);
			}
		}
	}
}
0