結果
| 問題 | No.1505 Zero-Product Ranges |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-05-14 23:47:32 |
| 言語 | Java (openjdk 25.0.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 814 bytes |
| 記録 | |
| コンパイル時間 | 4,063 ms |
| コンパイル使用メモリ | 77,532 KB |
| 実行使用メモリ | 56,364 KB |
| 最終ジャッジ日時 | 2024-10-02 06:05:04 |
| 合計ジャッジ時間 | 12,676 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 2 RE * 47 |
ソースコード
import java.util.Scanner;
public class No1505 {
private static long nCr(int n, int r)
{
if (n < r || n <= 0 || r <= 0) {
return 0;
}
return fact(n) / (fact(r) *
fact(n - r));
}
// Returns factorial of n
private static long fact(int n)
{
long res = 1;
for (int i = 2; i <= n; i++)
res = res * i;
return res;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int j = -1;
long cnt = nCr(N, 2) + 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, 2) + i-j;
}
j = -1;
}
}
if (j >= 0) {
cnt -= nCr(i-j, 2) + i-j;
}
scan.close();
System.out.println(cnt);
}
}