結果

問題 No.1505 Zero-Product Ranges
ユーザー ks2mks2m
提出日時 2021-05-14 22:08:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 750 ms / 2,000 ms
コード長 525 bytes
コンパイル時間 2,325 ms
コンパイル使用メモリ 75,088 KB
実行使用メモリ 63,892 KB
最終ジャッジ日時 2024-04-10 00:24:51
合計ジャッジ時間 29,248 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
54,264 KB
testcase_01 AC 126 ms
54,060 KB
testcase_02 AC 138 ms
54,048 KB
testcase_03 AC 750 ms
62,168 KB
testcase_04 AC 711 ms
60,708 KB
testcase_05 AC 519 ms
59,012 KB
testcase_06 AC 509 ms
59,256 KB
testcase_07 AC 447 ms
61,316 KB
testcase_08 AC 465 ms
59,088 KB
testcase_09 AC 460 ms
58,988 KB
testcase_10 AC 490 ms
59,356 KB
testcase_11 AC 533 ms
59,428 KB
testcase_12 AC 443 ms
59,260 KB
testcase_13 AC 553 ms
59,252 KB
testcase_14 AC 548 ms
59,232 KB
testcase_15 AC 723 ms
63,644 KB
testcase_16 AC 704 ms
63,560 KB
testcase_17 AC 672 ms
61,436 KB
testcase_18 AC 725 ms
63,496 KB
testcase_19 AC 129 ms
54,200 KB
testcase_20 AC 130 ms
53,988 KB
testcase_21 AC 152 ms
54,152 KB
testcase_22 AC 686 ms
63,496 KB
testcase_23 AC 649 ms
63,892 KB
testcase_24 AC 662 ms
63,244 KB
testcase_25 AC 701 ms
60,428 KB
testcase_26 AC 624 ms
63,596 KB
testcase_27 AC 574 ms
62,548 KB
testcase_28 AC 704 ms
63,172 KB
testcase_29 AC 701 ms
63,176 KB
testcase_30 AC 715 ms
63,556 KB
testcase_31 AC 661 ms
62,896 KB
testcase_32 AC 582 ms
59,388 KB
testcase_33 AC 519 ms
59,052 KB
testcase_34 AC 539 ms
59,288 KB
testcase_35 AC 497 ms
59,276 KB
testcase_36 AC 498 ms
59,200 KB
testcase_37 AC 516 ms
59,056 KB
testcase_38 AC 538 ms
59,340 KB
testcase_39 AC 527 ms
59,168 KB
testcase_40 AC 557 ms
59,072 KB
testcase_41 AC 541 ms
59,184 KB
testcase_42 AC 242 ms
57,236 KB
testcase_43 AC 272 ms
58,704 KB
testcase_44 AC 254 ms
58,112 KB
testcase_45 AC 266 ms
58,424 KB
testcase_46 AC 245 ms
57,632 KB
testcase_47 AC 271 ms
58,436 KB
testcase_48 AC 241 ms
57,676 KB
testcase_49 AC 212 ms
57,172 KB
testcase_50 AC 248 ms
57,848 KB
testcase_51 AC 276 ms
58,296 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