結果

問題 No.2053 12345...
ユーザー ks2mks2m
提出日時 2022-08-21 12:54:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 291 ms / 2,000 ms
コード長 658 bytes
コンパイル時間 4,070 ms
コンパイル使用メモリ 74,260 KB
実行使用メモリ 71,548 KB
最終ジャッジ日時 2024-04-18 12:42:14
合計ジャッジ時間 9,532 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
50,068 KB
testcase_01 AC 51 ms
50,024 KB
testcase_02 AC 82 ms
51,428 KB
testcase_03 AC 161 ms
57,852 KB
testcase_04 AC 250 ms
63,096 KB
testcase_05 AC 132 ms
54,188 KB
testcase_06 AC 225 ms
63,224 KB
testcase_07 AC 202 ms
60,576 KB
testcase_08 AC 198 ms
60,464 KB
testcase_09 AC 237 ms
63,720 KB
testcase_10 AC 271 ms
67,884 KB
testcase_11 AC 124 ms
53,992 KB
testcase_12 AC 98 ms
51,836 KB
testcase_13 AC 279 ms
65,112 KB
testcase_14 AC 189 ms
55,684 KB
testcase_15 AC 178 ms
57,844 KB
testcase_16 AC 158 ms
56,556 KB
testcase_17 AC 126 ms
54,512 KB
testcase_18 AC 290 ms
68,068 KB
testcase_19 AC 253 ms
63,344 KB
testcase_20 AC 109 ms
52,012 KB
testcase_21 AC 205 ms
60,264 KB
testcase_22 AC 57 ms
49,876 KB
testcase_23 AC 122 ms
53,948 KB
testcase_24 AC 169 ms
57,476 KB
testcase_25 AC 291 ms
71,548 KB
testcase_26 AC 178 ms
60,268 KB
testcase_27 AC 150 ms
56,848 KB
testcase_28 AC 159 ms
57,732 KB
testcase_29 AC 224 ms
63,472 KB
testcase_30 AC 162 ms
57,512 KB
testcase_31 AC 222 ms
63,364 KB
testcase_32 AC 261 ms
67,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		long ans = 0;
		int r = 1;
		for (int l = 0; l < n; l++) {
			r = Math.max(r, l + 1);
			while (r < n) {
				if (a[r - 1] + 1 == a[r]) {
					r++;
				} else {
					break;
				}
			}
			ans += r - l - 1;
		}
		System.out.println(ans);
	}
}
0