結果

問題 No.1687 What the Heck?
ユーザー merlinmerlin
提出日時 2021-09-24 21:51:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 665 bytes
コンパイル時間 2,630 ms
コンパイル使用メモリ 71,416 KB
実行使用メモリ 66,196 KB
最終ジャッジ日時 2023-09-18 21:12:54
合計ジャッジ時間 6,077 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,132 KB
testcase_01 AC 42 ms
49,544 KB
testcase_02 AC 43 ms
49,160 KB
testcase_03 AC 43 ms
49,252 KB
testcase_04 AC 42 ms
49,636 KB
testcase_05 AC 43 ms
49,220 KB
testcase_06 AC 43 ms
47,836 KB
testcase_07 AC 166 ms
58,284 KB
testcase_08 AC 197 ms
60,640 KB
testcase_09 AC 161 ms
57,632 KB
testcase_10 AC 141 ms
55,436 KB
testcase_11 AC 148 ms
55,256 KB
testcase_12 AC 263 ms
65,196 KB
testcase_13 AC 266 ms
65,344 KB
testcase_14 AC 273 ms
65,496 KB
testcase_15 AC 270 ms
65,412 KB
testcase_16 AC 277 ms
63,132 KB
testcase_17 AC 83 ms
52,400 KB
testcase_18 AC 269 ms
66,196 KB
testcase_19 AC 54 ms
50,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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,i,pos[]=new int[n+1];

        String s[]=bu.readLine().split(" ");
        for(i=0;i<n;i++)
        {
            a=Integer.parseInt(s[i]);
            pos[a]=i+1;
        }

        long ans=0,pre=pos[1];
        for(i=2;i<=n;i++)
        {
            ans=Math.max(ans,pre-pos[i]);
            pre+=pos[i];
        }

        System.out.println(ans);
    }
}
0