結果
| 問題 |
No.1505 Zero-Product Ranges
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-05-14 23:38:19 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 811 bytes |
| コンパイル時間 | 3,636 ms |
| コンパイル使用メモリ | 77,412 KB |
| 実行使用メモリ | 53,128 KB |
| 最終ジャッジ日時 | 2024-10-02 05:44:27 |
| 合計ジャッジ時間 | 30,206 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 3 WA * 46 |
ソースコード
import java.util.Scanner;
public class No1505 {
private static int 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 int fact(int n)
{
int 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;
int 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);
}
}