結果

問題 No.1687 What the Heck?
ユーザー tentententen
提出日時 2021-10-11 10:13:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 1,125 bytes
コンパイル時間 3,177 ms
コンパイル使用メモリ 74,544 KB
実行使用メモリ 57,932 KB
最終ジャッジ日時 2023-10-13 10:41:44
合計ジャッジ時間 8,307 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,452 KB
testcase_01 AC 45 ms
49,428 KB
testcase_02 AC 46 ms
49,292 KB
testcase_03 AC 45 ms
49,344 KB
testcase_04 AC 46 ms
49,444 KB
testcase_05 AC 45 ms
49,408 KB
testcase_06 AC 45 ms
49,332 KB
testcase_07 AC 178 ms
54,764 KB
testcase_08 AC 207 ms
55,876 KB
testcase_09 AC 182 ms
55,516 KB
testcase_10 AC 146 ms
55,044 KB
testcase_11 AC 166 ms
55,320 KB
testcase_12 AC 255 ms
57,796 KB
testcase_13 AC 244 ms
57,560 KB
testcase_14 AC 236 ms
57,880 KB
testcase_15 AC 241 ms
57,444 KB
testcase_16 AC 240 ms
57,432 KB
testcase_17 AC 106 ms
52,124 KB
testcase_18 AC 240 ms
57,932 KB
testcase_19 AC 57 ms
50,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] arr = new int[n + 1];
        for (int i = 0; i < n; i++) {
            arr[sc.nextInt()] = i + 1;
        }
        long ans = 0;
        long total = n * (n + 1L) / 2;
        for (int i = n; i >= 1; i--) {
            ans = Math.max(ans, total - arr[i] * 2);
            total -= arr[i];
        }
        System.out.println(ans);
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0