結果

問題 No.1505 Zero-Product Ranges
ユーザー 小野寺健
提出日時 2021-05-15 00:01:34
言語 Java
(openjdk 23)
結果
AC  
実行時間 761 ms / 2,000 ms
コード長 613 bytes
コンパイル時間 4,947 ms
コンパイル使用メモリ 77,088 KB
実行使用メモリ 63,932 KB
最終ジャッジ日時 2024-10-02 06:42:30
合計ジャッジ時間 29,415 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

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