結果

問題 No.2053 12345...
ユーザー viral8
提出日時 2022-10-01 10:57:53
言語 Java
(openjdk 23)
結果
AC  
実行時間 906 ms / 2,000 ms
コード長 544 bytes
コンパイル時間 2,248 ms
コンパイル使用メモリ 74,464 KB
実行使用メモリ 57,656 KB
最終ジャッジ日時 2024-12-23 15:34:50
合計ジャッジ時間 21,787 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int now = sc.nextInt();
        long count = 1;
        long ans = 0;
        while(--N>0){
            int next = sc.nextInt();
            if(++now==next)
                ++count;
            else{
                now = next;
                ans += count*(count-1)/2;
                count = 1;
            }
        }
        System.out.println(ans+count*(count-1)/2);
    }
}
0