結果

問題 No.1765 While Shining
ユーザー merlinmerlin
提出日時 2021-11-26 22:34:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 236 ms / 2,000 ms
コード長 657 bytes
コンパイル時間 2,020 ms
コンパイル使用メモリ 72,760 KB
実行使用メモリ 68,256 KB
最終ジャッジ日時 2023-09-12 05:12:33
合計ジャッジ時間 7,141 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,568 KB
testcase_01 AC 42 ms
49,408 KB
testcase_02 AC 43 ms
49,504 KB
testcase_03 AC 42 ms
49,288 KB
testcase_04 AC 44 ms
49,088 KB
testcase_05 AC 45 ms
49,332 KB
testcase_06 AC 43 ms
49,248 KB
testcase_07 AC 43 ms
49,116 KB
testcase_08 AC 48 ms
49,500 KB
testcase_09 AC 159 ms
60,496 KB
testcase_10 AC 205 ms
64,216 KB
testcase_11 AC 209 ms
64,364 KB
testcase_12 AC 194 ms
64,108 KB
testcase_13 AC 206 ms
63,868 KB
testcase_14 AC 226 ms
67,324 KB
testcase_15 AC 209 ms
67,536 KB
testcase_16 AC 230 ms
67,716 KB
testcase_17 AC 222 ms
67,992 KB
testcase_18 AC 224 ms
67,472 KB
testcase_19 AC 224 ms
67,820 KB
testcase_20 AC 236 ms
67,836 KB
testcase_21 AC 223 ms
67,636 KB
testcase_22 AC 216 ms
68,120 KB
testcase_23 AC 226 ms
68,256 KB
testcase_24 AC 219 ms
67,728 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());
        String s[]=bu.readLine().split(" ");
        int i,a[]=new int[n];
        for(i=0;i<n;i++) a[i]=Integer.parseInt(s[i]);

        int dp[]=new int[n]; long ans=0;
        for(i=n-2;i>=0;i--)
        {
            if(a[i]!=a[i+1]) dp[i]=dp[i+1]+1;
            else dp[i]=1;
            if(a[i]==1) ans+=dp[i];
        }
        System.out.println(ans);
    }
}
0