結果
問題 | No.1687 What the Heck? |
ユーザー | merlin |
提出日時 | 2021-09-24 21:38:21 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 820 bytes |
コンパイル時間 | 3,448 ms |
コンパイル使用メモリ | 72,424 KB |
実行使用メモリ | 88,732 KB |
最終ジャッジ日時 | 2023-09-18 20:55:55 |
合計ジャッジ時間 | 10,865 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
49,496 KB |
testcase_01 | AC | 44 ms
49,500 KB |
testcase_02 | WA | - |
testcase_03 | AC | 45 ms
49,492 KB |
testcase_04 | AC | 44 ms
49,480 KB |
testcase_05 | AC | 45 ms
49,336 KB |
testcase_06 | AC | 44 ms
49,528 KB |
testcase_07 | AC | 408 ms
65,812 KB |
testcase_08 | AC | 479 ms
68,440 KB |
testcase_09 | WA | - |
testcase_10 | AC | 308 ms
60,696 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 722 ms
87,080 KB |
testcase_14 | AC | 711 ms
86,316 KB |
testcase_15 | AC | 714 ms
86,544 KB |
testcase_16 | AC | 763 ms
86,348 KB |
testcase_17 | AC | 167 ms
57,512 KB |
testcase_18 | AC | 731 ms
86,564 KB |
testcase_19 | AC | 98 ms
52,464 KB |
ソースコード
import java.io.*; import java.util.*; class Main { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int n=Integer.parseInt(bu.readLine()); int a[]=new int[n],b,i; long ans=0; String s[]=bu.readLine().split(" "); TreeSet<Integer> ts=new TreeSet<>(); for(i=0;i<n;i++) { a[i]=Integer.parseInt(s[i]); ts.add(i+1); } for(i=n-1;i>=0;i--) if(ts.higher(a[i])!=null) { int del=ts.higher(a[i]); ts.remove(del); ans+=i+1; } else if(ts.contains(a[i])) ts.remove(a[i]); else ans-=i+1; System.out.println(ans); } }