結果

問題 No.2053 12345...
ユーザー tentententen
提出日時 2023-03-01 11:27:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 248 ms / 2,000 ms
コード長 1,938 bytes
コンパイル時間 5,541 ms
コンパイル使用メモリ 88,072 KB
実行使用メモリ 60,824 KB
最終ジャッジ日時 2023-10-14 16:13:59
合計ジャッジ時間 13,936 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,416 KB
testcase_01 AC 45 ms
49,224 KB
testcase_02 AC 85 ms
51,912 KB
testcase_03 AC 180 ms
55,968 KB
testcase_04 AC 228 ms
57,884 KB
testcase_05 AC 132 ms
54,940 KB
testcase_06 AC 226 ms
57,444 KB
testcase_07 AC 198 ms
55,428 KB
testcase_08 AC 186 ms
53,180 KB
testcase_09 AC 227 ms
57,520 KB
testcase_10 AC 244 ms
60,064 KB
testcase_11 AC 120 ms
55,168 KB
testcase_12 AC 122 ms
52,700 KB
testcase_13 AC 245 ms
58,576 KB
testcase_14 AC 181 ms
55,376 KB
testcase_15 AC 173 ms
55,196 KB
testcase_16 AC 155 ms
54,772 KB
testcase_17 AC 151 ms
55,248 KB
testcase_18 AC 248 ms
60,708 KB
testcase_19 AC 233 ms
57,828 KB
testcase_20 AC 107 ms
52,240 KB
testcase_21 AC 181 ms
55,164 KB
testcase_22 AC 60 ms
51,116 KB
testcase_23 AC 126 ms
52,708 KB
testcase_24 AC 170 ms
55,428 KB
testcase_25 AC 243 ms
60,120 KB
testcase_26 AC 190 ms
55,168 KB
testcase_27 AC 165 ms
55,080 KB
testcase_28 AC 144 ms
55,132 KB
testcase_29 AC 221 ms
57,700 KB
testcase_30 AC 157 ms
55,076 KB
testcase_31 AC 214 ms
57,384 KB
testcase_32 AC 244 ms
60,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 prev = sc.nextInt();
        int length = 0;
        long ans = 0;
        for (int i = 0; i < n - 1; i++) {
            int x = sc.nextInt();
            if (x - prev == 1) {
                length++;
            } else {
                ans += getCount(length);
                length = 0;
            }
            prev = x;
        }
        ans += getCount(length);
        System.out.println(ans);
    }
    
    static long getCount(long x) {
        return (x + 1) * x / 2;
    }
}
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();
    }
    
}
0