結果
問題 | No.318 学学学学学 |
ユーザー | threepipes_s |
提出日時 | 2015-12-11 18:58:54 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 604 ms / 2,000 ms |
コード長 | 3,309 bytes |
コンパイル時間 | 2,716 ms |
コンパイル使用メモリ | 92,596 KB |
実行使用メモリ | 77,340 KB |
最終ジャッジ日時 | 2024-06-22 15:34:00 |
合計ジャッジ時間 | 13,292 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 162 ms
54,928 KB |
testcase_01 | AC | 220 ms
60,604 KB |
testcase_02 | AC | 232 ms
61,372 KB |
testcase_03 | AC | 197 ms
55,844 KB |
testcase_04 | AC | 223 ms
60,088 KB |
testcase_05 | AC | 464 ms
77,212 KB |
testcase_06 | AC | 604 ms
74,876 KB |
testcase_07 | AC | 538 ms
72,128 KB |
testcase_08 | AC | 488 ms
66,448 KB |
testcase_09 | AC | 470 ms
65,616 KB |
testcase_10 | AC | 397 ms
65,768 KB |
testcase_11 | AC | 458 ms
77,340 KB |
testcase_12 | AC | 488 ms
75,032 KB |
testcase_13 | AC | 459 ms
70,976 KB |
testcase_14 | AC | 417 ms
65,852 KB |
testcase_15 | AC | 404 ms
66,352 KB |
testcase_16 | AC | 378 ms
65,228 KB |
testcase_17 | AC | 485 ms
75,188 KB |
testcase_18 | AC | 454 ms
75,024 KB |
testcase_19 | AC | 464 ms
74,976 KB |
testcase_20 | AC | 346 ms
64,172 KB |
testcase_21 | AC | 71 ms
51,468 KB |
testcase_22 | AC | 73 ms
51,268 KB |
testcase_23 | AC | 69 ms
51,160 KB |
testcase_24 | AC | 68 ms
51,304 KB |
testcase_25 | AC | 77 ms
51,316 KB |
testcase_26 | AC | 73 ms
51,432 KB |
testcase_27 | AC | 73 ms
51,088 KB |
testcase_28 | AC | 73 ms
50,920 KB |
ソースコード
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.BitSet; import java.util.HashMap; import java.util.TreeSet; public class Main{ public static void main(String[] args){ try {(new Solve()).solve();} catch (NumberFormatException | IOException e) {e.printStackTrace();} } } class Solve{ void solve() throws NumberFormatException, IOException{ final ContestScanner in = new ContestScanner(); ContestWriter out = new ContestWriter(); int n = in.nextInt(); int[] a = new int[n]; int[] b = new int[n]; HashMap<Integer, Integer> first = new HashMap<>(); for(int i=0; i<n; i++){ a[i] = in.nextInt(); b[i] = a[i]; if(first.containsKey(a[i])) continue; first.put(a[i], i); } HashMap<Integer, Integer> second = new HashMap<>(); for(int i=n-1; i>=0; i--){ if(second.containsKey(a[i])){ if(first.get(a[i])!=i) a[i] = 0; }else if(first.get(a[i])==i){ a[i] = -a[i]; }else{ second.put(a[i], i); } } TreeSet<Integer> set = new TreeSet<>((e1,e2)->e2-e1); for(int i=0; i<n; i++){ if(a[i]>0){ if(set.contains(a[i])){ final int t = set.first(); set.remove(a[i]); a[i] = t; continue; } else set.add(a[i]); }else if(a[i]<0){ a[i] = Math.max(-a[i], set.isEmpty()?0:set.first()); continue; } if(!set.isEmpty()) a[i] = set.first(); } StringBuilder sb = new StringBuilder(); for(int i=0; i<n; i++){ if(a[i]==0) a[i] = b[i]; sb.append(a[i]+" "); } out.println(sb.toString().trim()); out.close(); } } class MultiSet<T> extends HashMap<T, Integer>{ @Override public Integer get(Object key){return containsKey(key)?super.get(key):0;} public void add(T key,int v){put(key,get(key)+v);} public void add(T key){put(key,get(key)+1);} } class ContestWriter{ private PrintWriter out; public ContestWriter(String filename) throws IOException {out = new PrintWriter(new BufferedWriter(new FileWriter(filename)));} public ContestWriter() throws IOException{out = new PrintWriter(System.out);} public void println(String str){out.println(str);} public void println(Object str){out.println(str);} public void print(String str){out.print(str);} public void close(){out.close();} } class ContestScanner { private BufferedReader reader; private String[] line; private int idx; public ContestScanner()throws FileNotFoundException {reader=new BufferedReader(new InputStreamReader(System.in));} public ContestScanner(String filename)throws FileNotFoundException {reader=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));} public String nextToken()throws IOException{if(line==null||line.length<=idx){ line=reader.readLine().trim().split(" ");idx=0;}return line[idx++];} public String readLine()throws IOException{return reader.readLine();} public long nextLong()throws IOException,NumberFormatException{return Long.parseLong(nextToken());} public int nextInt()throws NumberFormatException,IOException{return(int)nextLong();} public double nextDouble()throws NumberFormatException,IOException {return Double.parseDouble(nextToken());} }