結果
問題 | No.1525 Meximum Sum |
ユーザー | tenten |
提出日時 | 2023-04-25 17:49:47 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 286 ms / 2,000 ms |
コード長 | 2,097 bytes |
コンパイル時間 | 2,944 ms |
コンパイル使用メモリ | 92,320 KB |
実行使用メモリ | 58,292 KB |
最終ジャッジ日時 | 2024-11-14 13:52:51 |
合計ジャッジ時間 | 10,594 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
50,180 KB |
testcase_01 | AC | 55 ms
50,192 KB |
testcase_02 | AC | 55 ms
50,492 KB |
testcase_03 | AC | 55 ms
50,412 KB |
testcase_04 | AC | 53 ms
50,448 KB |
testcase_05 | AC | 55 ms
50,180 KB |
testcase_06 | AC | 54 ms
50,412 KB |
testcase_07 | AC | 55 ms
50,316 KB |
testcase_08 | AC | 217 ms
55,844 KB |
testcase_09 | AC | 266 ms
58,104 KB |
testcase_10 | AC | 177 ms
55,892 KB |
testcase_11 | AC | 189 ms
55,132 KB |
testcase_12 | AC | 236 ms
58,188 KB |
testcase_13 | AC | 279 ms
58,092 KB |
testcase_14 | AC | 274 ms
57,936 KB |
testcase_15 | AC | 280 ms
58,172 KB |
testcase_16 | AC | 268 ms
57,808 KB |
testcase_17 | AC | 286 ms
58,292 KB |
testcase_18 | AC | 277 ms
58,164 KB |
testcase_19 | AC | 279 ms
58,252 KB |
testcase_20 | AC | 267 ms
57,792 KB |
testcase_21 | AC | 282 ms
58,040 KB |
testcase_22 | AC | 262 ms
57,860 KB |
testcase_23 | AC | 263 ms
57,868 KB |
testcase_24 | AC | 267 ms
57,896 KB |
testcase_25 | AC | 259 ms
57,840 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int[] positions = new int[n]; for (int i = 0; i < n; i++) { positions[sc.nextInt()] = i; } long[] counts = new long[n]; int left = Integer.MAX_VALUE; int right = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { left = Math.min(left, positions[i]); right = Math.max(right, positions[i]); counts[i] = (left + 1L) * (n - right); } long ans = 0; long total = 0; for (int i = n - 1; i >= 0; i--) { ans += (counts[i] - total) * (i + 1); total = counts[i]; } System.out.println(ans); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); 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 int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }