結果

問題 No.1505 Zero-Product Ranges
ユーザー ks2mks2m
提出日時 2021-05-14 22:08:27
言語 Java17
(openjdk 17.0.1)
結果
AC  
実行時間 505 ms / 2,000 ms
コード長 525 bytes
コンパイル時間 2,474 ms
使用メモリ 50,444 KB
最終ジャッジ日時 2022-11-25 18:33:21
合計ジャッジ時間 19,909 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 76 ms
37,428 KB
testcase_01 AC 77 ms
37,440 KB
testcase_02 AC 78 ms
37,568 KB
testcase_03 AC 442 ms
48,880 KB
testcase_04 AC 434 ms
49,880 KB
testcase_05 AC 324 ms
44,520 KB
testcase_06 AC 312 ms
45,436 KB
testcase_07 AC 270 ms
44,676 KB
testcase_08 AC 294 ms
44,628 KB
testcase_09 AC 287 ms
44,776 KB
testcase_10 AC 287 ms
44,804 KB
testcase_11 AC 304 ms
44,652 KB
testcase_12 AC 266 ms
44,856 KB
testcase_13 AC 446 ms
46,056 KB
testcase_14 AC 325 ms
44,976 KB
testcase_15 AC 424 ms
49,584 KB
testcase_16 AC 423 ms
50,428 KB
testcase_17 AC 464 ms
49,316 KB
testcase_18 AC 505 ms
50,164 KB
testcase_19 AC 78 ms
37,476 KB
testcase_20 AC 75 ms
37,308 KB
testcase_21 AC 91 ms
37,712 KB
testcase_22 AC 477 ms
48,976 KB
testcase_23 AC 474 ms
50,164 KB
testcase_24 AC 456 ms
50,444 KB
testcase_25 AC 473 ms
49,640 KB
testcase_26 AC 452 ms
49,188 KB
testcase_27 AC 418 ms
49,472 KB
testcase_28 AC 412 ms
49,772 KB
testcase_29 AC 464 ms
49,852 KB
testcase_30 AC 480 ms
49,140 KB
testcase_31 AC 462 ms
50,132 KB
testcase_32 AC 375 ms
44,988 KB
testcase_33 AC 311 ms
45,020 KB
testcase_34 AC 396 ms
45,152 KB
testcase_35 AC 295 ms
44,168 KB
testcase_36 AC 330 ms
47,940 KB
testcase_37 AC 330 ms
45,196 KB
testcase_38 AC 326 ms
44,948 KB
testcase_39 AC 299 ms
45,236 KB
testcase_40 AC 374 ms
44,980 KB
testcase_41 AC 379 ms
46,824 KB
testcase_42 AC 208 ms
44,016 KB
testcase_43 AC 230 ms
44,216 KB
testcase_44 AC 215 ms
44,052 KB
testcase_45 AC 208 ms
43,932 KB
testcase_46 AC 188 ms
44,048 KB
testcase_47 AC 230 ms
44,368 KB
testcase_48 AC 202 ms
44,248 KB
testcase_49 AC 187 ms
43,560 KB
testcase_50 AC 202 ms
44,108 KB
testcase_51 AC 207 ms
44,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		long ans = (long) n * (n + 1) / 2;
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] == 1) {
				cnt++;
			} else {
				ans -= (long) cnt * (cnt + 1) / 2;
				cnt = 0;
			}
		}
		ans -= (long) cnt * (cnt + 1) / 2;
		System.out.println(ans);
	}
}
0