結果
| 問題 |
No.1505 Zero-Product Ranges
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-05-14 23:34:53 |
| 言語 | Java (openjdk 23) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 759 bytes |
| コンパイル時間 | 3,764 ms |
| コンパイル使用メモリ | 78,852 KB |
| 実行使用メモリ | 41,848 KB |
| 最終ジャッジ日時 | 2024-10-02 05:36:52 |
| 合計ジャッジ時間 | 12,268 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 2 RE * 47 |
ソースコード
import java.util.Scanner;
public class No1505 {
private static int nCr(int n, int r)
{
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);
}
}