結果

問題 No.1505 Zero-Product Ranges
ユーザー ks2m
提出日時 2021-05-14 22:08:27
言語 Java
(openjdk 23)
結果
AC  
実行時間 722 ms / 2,000 ms
コード長 525 bytes
コンパイル時間 2,205 ms
コンパイル使用メモリ 74,828 KB
実行使用メモリ 63,956 KB
最終ジャッジ日時 2024-10-02 01:23:21
合計ジャッジ時間 28,061 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

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