提出 #1411833


ソースコード 拡げる

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N, P;
		long ans = 0;

		N = Integer.parseInt(sc.next());
		P = Integer.parseInt(sc.next());

		int[] A = new int[N];
		int oCount = 0;
		int eCount = 0;

		for(int i = 0; i < N; i++){
			A[i] = Integer.parseInt(sc.next());
		}

		for(int i = 0; i < N; i++){
			if(A[i] % 2 != 0){
				oCount++;
			}else{
				eCount++;
			}
		}

		if(P == 0){
			if(oCount >= 2){
				int o = oCount - (oCount % 2);
				while(o > 0){
					ans += comb(oCount, o);
					o -= 2;
				}
			}
			ans += 1;
		}else{
			int o = oCount - ((oCount+1) % 2);
			while(o > 0){
				ans += comb(oCount, o);
				o -= 2;
			}
		}

		ans *= Math.pow(2, eCount);

		System.out.println(ans);

	}

	public static int comb(int n, int r){
		if(r == 0 || r == n) return 1;
		else return comb(n-1, r-1) + comb(n-1, r);
	}

}

提出情報

提出日時
問題 A - Biscuits
ユーザ pocket
言語 Java8 (OpenJDK 1.8.0)
得点 200
コード長 976 Byte
結果 AC
実行時間 204 ms
メモリ 21972 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 200 / 200
結果
AC × 4
AC × 16
セット名 テストケース
Sample sample1.txt, sample2.txt, sample3.txt, sample4.txt
All sample1.txt, sample2.txt, sample3.txt, sample4.txt, in1.txt, in2.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, sample1.txt, sample2.txt, sample3.txt, sample4.txt
ケース名 結果 実行時間 メモリ
in1.txt AC 204 ms 18644 KiB
in2.txt AC 157 ms 18900 KiB
in3.txt AC 91 ms 21716 KiB
in4.txt AC 89 ms 21844 KiB
in5.txt AC 89 ms 21716 KiB
in6.txt AC 200 ms 16972 KiB
in7.txt AC 91 ms 18640 KiB
in8.txt AC 88 ms 18644 KiB
sample1.txt AC 90 ms 21972 KiB
sample2.txt AC 88 ms 18516 KiB
sample3.txt AC 89 ms 18900 KiB
sample4.txt AC 119 ms 19924 KiB