結果
| 問題 | 
                            No.1505 Zero-Product Ranges
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-05-14 23:38:59 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 812 bytes | 
| コンパイル時間 | 3,523 ms | 
| コンパイル使用メモリ | 77,164 KB | 
| 実行使用メモリ | 41,696 KB | 
| 最終ジャッジ日時 | 2024-10-02 05:45:31 | 
| 合計ジャッジ時間 | 11,861 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 2 RE * 47 | 
ソースコード
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);
	}
}