結果

問題 No.1505 Zero-Product Ranges
ユーザー 小野寺健小野寺健
提出日時 2021-05-15 00:01:34
言語 Java17
(openjdk 17.0.1)
結果
AC  
実行時間 594 ms / 2,000 ms
コード長 613 bytes
コンパイル時間 5,855 ms
使用メモリ 57,576 KB
最終ジャッジ日時 2022-11-26 00:26:42
合計ジャッジ時間 26,999 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 86 ms
37,484 KB
testcase_01 AC 90 ms
37,548 KB
testcase_02 AC 92 ms
37,520 KB
testcase_03 AC 526 ms
49,236 KB
testcase_04 AC 580 ms
49,648 KB
testcase_05 AC 343 ms
45,012 KB
testcase_06 AC 329 ms
48,928 KB
testcase_07 AC 297 ms
44,460 KB
testcase_08 AC 367 ms
47,528 KB
testcase_09 AC 311 ms
44,516 KB
testcase_10 AC 357 ms
44,624 KB
testcase_11 AC 354 ms
48,176 KB
testcase_12 AC 342 ms
44,600 KB
testcase_13 AC 394 ms
45,452 KB
testcase_14 AC 420 ms
44,820 KB
testcase_15 AC 510 ms
48,108 KB
testcase_16 AC 526 ms
50,604 KB
testcase_17 AC 594 ms
48,908 KB
testcase_18 AC 482 ms
50,556 KB
testcase_19 AC 87 ms
37,332 KB
testcase_20 AC 84 ms
37,656 KB
testcase_21 AC 99 ms
37,760 KB
testcase_22 AC 518 ms
49,680 KB
testcase_23 AC 538 ms
57,576 KB
testcase_24 AC 454 ms
50,908 KB
testcase_25 AC 471 ms
47,664 KB
testcase_26 AC 514 ms
48,412 KB
testcase_27 AC 509 ms
49,528 KB
testcase_28 AC 479 ms
51,044 KB
testcase_29 AC 537 ms
50,864 KB
testcase_30 AC 503 ms
49,680 KB
testcase_31 AC 559 ms
49,344 KB
testcase_32 AC 430 ms
48,204 KB
testcase_33 AC 406 ms
48,156 KB
testcase_34 AC 437 ms
47,312 KB
testcase_35 AC 409 ms
48,196 KB
testcase_36 AC 374 ms
47,892 KB
testcase_37 AC 400 ms
44,496 KB
testcase_38 AC 366 ms
48,116 KB
testcase_39 AC 365 ms
46,568 KB
testcase_40 AC 382 ms
46,320 KB
testcase_41 AC 464 ms
49,692 KB
testcase_42 AC 207 ms
44,604 KB
testcase_43 AC 270 ms
44,068 KB
testcase_44 AC 218 ms
44,176 KB
testcase_45 AC 223 ms
44,060 KB
testcase_46 AC 216 ms
43,908 KB
testcase_47 AC 230 ms
44,320 KB
testcase_48 AC 213 ms
44,004 KB
testcase_49 AC 201 ms
43,792 KB
testcase_50 AC 224 ms
44,636 KB
testcase_51 AC 246 ms
44,952 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