結果

問題 No.2053 12345...
ユーザー tentententen
提出日時 2022-08-22 12:56:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 266 ms / 2,000 ms
コード長 1,274 bytes
コンパイル時間 2,283 ms
コンパイル使用メモリ 77,400 KB
実行使用メモリ 50,692 KB
最終ジャッジ日時 2024-04-18 13:22:21
合計ジャッジ時間 9,949 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
37,056 KB
testcase_01 AC 52 ms
37,228 KB
testcase_02 AC 90 ms
39,064 KB
testcase_03 AC 151 ms
44,612 KB
testcase_04 AC 230 ms
47,144 KB
testcase_05 AC 139 ms
42,792 KB
testcase_06 AC 239 ms
47,280 KB
testcase_07 AC 189 ms
45,848 KB
testcase_08 AC 187 ms
45,020 KB
testcase_09 AC 240 ms
46,796 KB
testcase_10 AC 266 ms
50,552 KB
testcase_11 AC 152 ms
41,244 KB
testcase_12 AC 125 ms
40,440 KB
testcase_13 AC 257 ms
48,140 KB
testcase_14 AC 193 ms
43,720 KB
testcase_15 AC 174 ms
43,708 KB
testcase_16 AC 170 ms
43,184 KB
testcase_17 AC 159 ms
43,356 KB
testcase_18 AC 263 ms
50,432 KB
testcase_19 AC 244 ms
46,992 KB
testcase_20 AC 117 ms
39,960 KB
testcase_21 AC 194 ms
44,652 KB
testcase_22 AC 68 ms
38,100 KB
testcase_23 AC 126 ms
40,856 KB
testcase_24 AC 170 ms
44,052 KB
testcase_25 AC 253 ms
48,404 KB
testcase_26 AC 205 ms
45,564 KB
testcase_27 AC 175 ms
43,436 KB
testcase_28 AC 163 ms
44,412 KB
testcase_29 AC 228 ms
46,776 KB
testcase_30 AC 186 ms
44,572 KB
testcase_31 AC 227 ms
46,504 KB
testcase_32 AC 264 ms
50,692 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[] values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        int left = 0;
        long ans = 0;
        for (int i = 1; i < n; i++) {
            if (values[i] - values[i - 1] == 1) {
                ans += i - left;
            } else {
                left = 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 double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0