結果

問題 No.1505 Zero-Product Ranges
ユーザー 小野寺健小野寺健
提出日時 2021-05-15 00:01:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 681 ms / 2,000 ms
コード長 613 bytes
コンパイル時間 3,168 ms
コンパイル使用メモリ 74,728 KB
実行使用メモリ 64,504 KB
最終ジャッジ日時 2024-04-10 05:10:21
合計ジャッジ時間 26,732 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
53,484 KB
testcase_01 AC 118 ms
53,984 KB
testcase_02 AC 105 ms
52,936 KB
testcase_03 AC 580 ms
64,504 KB
testcase_04 AC 561 ms
63,732 KB
testcase_05 AC 472 ms
59,052 KB
testcase_06 AC 457 ms
58,968 KB
testcase_07 AC 387 ms
59,080 KB
testcase_08 AC 423 ms
58,952 KB
testcase_09 AC 406 ms
59,156 KB
testcase_10 AC 415 ms
59,024 KB
testcase_11 AC 417 ms
59,328 KB
testcase_12 AC 375 ms
58,940 KB
testcase_13 AC 437 ms
58,128 KB
testcase_14 AC 433 ms
59,176 KB
testcase_15 AC 531 ms
60,320 KB
testcase_16 AC 588 ms
64,056 KB
testcase_17 AC 598 ms
63,880 KB
testcase_18 AC 681 ms
63,464 KB
testcase_19 AC 117 ms
54,136 KB
testcase_20 AC 114 ms
54,116 KB
testcase_21 AC 122 ms
53,196 KB
testcase_22 AC 600 ms
63,672 KB
testcase_23 AC 639 ms
63,596 KB
testcase_24 AC 527 ms
62,848 KB
testcase_25 AC 596 ms
63,524 KB
testcase_26 AC 601 ms
60,564 KB
testcase_27 AC 626 ms
62,896 KB
testcase_28 AC 614 ms
60,472 KB
testcase_29 AC 616 ms
63,216 KB
testcase_30 AC 641 ms
63,296 KB
testcase_31 AC 631 ms
64,456 KB
testcase_32 AC 472 ms
59,016 KB
testcase_33 AC 484 ms
59,344 KB
testcase_34 AC 529 ms
59,236 KB
testcase_35 AC 490 ms
59,044 KB
testcase_36 AC 472 ms
59,196 KB
testcase_37 AC 489 ms
59,156 KB
testcase_38 AC 453 ms
59,072 KB
testcase_39 AC 476 ms
59,288 KB
testcase_40 AC 510 ms
59,320 KB
testcase_41 AC 499 ms
59,164 KB
testcase_42 AC 223 ms
57,560 KB
testcase_43 AC 250 ms
58,528 KB
testcase_44 AC 240 ms
58,028 KB
testcase_45 AC 241 ms
58,196 KB
testcase_46 AC 227 ms
57,552 KB
testcase_47 AC 272 ms
58,712 KB
testcase_48 AC 229 ms
57,756 KB
testcase_49 AC 206 ms
57,280 KB
testcase_50 AC 225 ms
58,016 KB
testcase_51 AC 255 ms
58,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No1505 {
	
	private static long nCr(int n)
	{
		if (n < 2 || n <= 0) {
			return 0L;
		}
		return (long)n * (long)(n-1) / 2L;
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int j = -1;
		long cnt = nCr(N) + N;
		int i = 0;
		for (; i < N; i++) {
			if (scan.nextInt() == 1) {
				if (j < 0) {
					j = i;
				}
			} else {
				if (j >= 0) {
					cnt -= nCr(i-j) + (long)(i-j);
				}
				j = -1;
			}
		}
		if (j >= 0) {
			cnt -= nCr(i-j) + (long)(i-j);
		}
		scan.close();
		System.out.println(cnt);
	}
}
0