結果
問題 | No.1525 Meximum Sum |
ユーザー | tenten |
提出日時 | 2023-04-25 17:49:47 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 286 ms / 2,000 ms |
コード長 | 2,097 bytes |
コンパイル時間 | 2,620 ms |
コンパイル使用メモリ | 88,860 KB |
実行使用メモリ | 47,632 KB |
最終ジャッジ日時 | 2024-04-26 22:17:23 |
合計ジャッジ時間 | 9,785 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
37,048 KB |
testcase_01 | AC | 54 ms
36,936 KB |
testcase_02 | AC | 54 ms
36,744 KB |
testcase_03 | AC | 53 ms
37,056 KB |
testcase_04 | AC | 52 ms
36,988 KB |
testcase_05 | AC | 51 ms
37,124 KB |
testcase_06 | AC | 50 ms
36,800 KB |
testcase_07 | AC | 50 ms
36,740 KB |
testcase_08 | AC | 241 ms
45,744 KB |
testcase_09 | AC | 262 ms
46,856 KB |
testcase_10 | AC | 166 ms
44,028 KB |
testcase_11 | AC | 178 ms
43,924 KB |
testcase_12 | AC | 252 ms
46,656 KB |
testcase_13 | AC | 280 ms
47,400 KB |
testcase_14 | AC | 276 ms
47,320 KB |
testcase_15 | AC | 279 ms
47,108 KB |
testcase_16 | AC | 279 ms
47,380 KB |
testcase_17 | AC | 272 ms
47,592 KB |
testcase_18 | AC | 282 ms
47,480 KB |
testcase_19 | AC | 267 ms
46,932 KB |
testcase_20 | AC | 286 ms
47,528 KB |
testcase_21 | AC | 278 ms
47,052 KB |
testcase_22 | AC | 269 ms
47,124 KB |
testcase_23 | AC | 269 ms
47,320 KB |
testcase_24 | AC | 273 ms
47,632 KB |
testcase_25 | AC | 268 ms
47,420 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(); } }