結果
問題 | No.1525 Meximum Sum |
ユーザー | tenten |
提出日時 | 2023-03-24 18:17:33 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 281 ms / 2,000 ms |
コード長 | 2,029 bytes |
コンパイル時間 | 2,829 ms |
コンパイル使用メモリ | 88,948 KB |
実行使用メモリ | 60,884 KB |
最終ジャッジ日時 | 2023-10-18 20:32:24 |
合計ジャッジ時間 | 9,183 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
53,472 KB |
testcase_01 | AC | 55 ms
52,404 KB |
testcase_02 | AC | 55 ms
52,360 KB |
testcase_03 | AC | 54 ms
53,480 KB |
testcase_04 | AC | 54 ms
51,432 KB |
testcase_05 | AC | 54 ms
53,480 KB |
testcase_06 | AC | 55 ms
53,480 KB |
testcase_07 | AC | 54 ms
53,488 KB |
testcase_08 | AC | 241 ms
58,476 KB |
testcase_09 | AC | 260 ms
60,884 KB |
testcase_10 | AC | 168 ms
58,432 KB |
testcase_11 | AC | 193 ms
58,508 KB |
testcase_12 | AC | 252 ms
60,832 KB |
testcase_13 | AC | 278 ms
60,592 KB |
testcase_14 | AC | 275 ms
60,612 KB |
testcase_15 | AC | 274 ms
60,548 KB |
testcase_16 | AC | 281 ms
60,776 KB |
testcase_17 | AC | 272 ms
60,664 KB |
testcase_18 | AC | 272 ms
60,668 KB |
testcase_19 | AC | 275 ms
60,708 KB |
testcase_20 | AC | 273 ms
60,664 KB |
testcase_21 | AC | 275 ms
58,916 KB |
testcase_22 | AC | 272 ms
60,536 KB |
testcase_23 | AC | 265 ms
60,764 KB |
testcase_24 | AC | 262 ms
60,668 KB |
testcase_25 | AC | 268 ms
60,884 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 + 1]; for (int i = 0; i < n; i++) { positions[sc.nextInt()] = i; } int left = positions[0]; int right = positions[0]; long ans = 0; long all = n * (n - 1L) / 2; for (int i = 0; i < n; i++) { long current = (left + 1L) * (n - right); ans += (all - current) * i; all = current; left = Math.min(left, positions[i + 1]); right = Math.max(right, positions[i + 1]); } ans += n; 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(); } }