結果
| 問題 | No.1505 Zero-Product Ranges |
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2021-05-14 22:08:27 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 448 ms / 2,000 ms |
| コード長 | 525 bytes |
| 記録 | |
| コンパイル時間 | 3,456 ms |
| コンパイル使用メモリ | 81,608 KB |
| 実行使用メモリ | 58,708 KB |
| 最終ジャッジ日時 | 2026-04-18 10:30:17 |
| 合計ジャッジ時間 | 19,762 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
ソースコード
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);
}
}
ks2m