結果

問題 No.462 6日知らずのコンピュータ
ユーザー tamago324_padtamago324_pad
提出日時 2016-12-25 03:49:16
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,064 bytes
コンパイル時間 3,507 ms
コンパイル使用メモリ 80,008 KB
実行使用メモリ 41,724 KB
最終ジャッジ日時 2024-05-08 14:10:46
合計ジャッジ時間 16,447 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
41,216 KB
testcase_01 AC 108 ms
40,296 KB
testcase_02 AC 130 ms
41,620 KB
testcase_03 AC 116 ms
40,292 KB
testcase_04 AC 121 ms
41,052 KB
testcase_05 AC 123 ms
41,224 KB
testcase_06 AC 108 ms
39,972 KB
testcase_07 AC 110 ms
40,076 KB
testcase_08 AC 118 ms
41,112 KB
testcase_09 AC 121 ms
41,188 KB
testcase_10 AC 108 ms
40,204 KB
testcase_11 AC 116 ms
41,128 KB
testcase_12 AC 127 ms
41,388 KB
testcase_13 AC 128 ms
41,608 KB
testcase_14 AC 129 ms
41,392 KB
testcase_15 WA -
testcase_16 AC 109 ms
39,588 KB
testcase_17 AC 114 ms
40,076 KB
testcase_18 AC 109 ms
39,968 KB
testcase_19 AC 120 ms
41,248 KB
testcase_20 AC 120 ms
41,588 KB
testcase_21 AC 125 ms
41,204 KB
testcase_22 AC 112 ms
40,344 KB
testcase_23 AC 128 ms
41,436 KB
testcase_24 AC 114 ms
40,604 KB
testcase_25 AC 133 ms
41,580 KB
testcase_26 AC 126 ms
41,244 KB
testcase_27 AC 110 ms
40,212 KB
testcase_28 AC 108 ms
40,152 KB
testcase_29 AC 130 ms
41,220 KB
testcase_30 AC 121 ms
41,464 KB
testcase_31 AC 121 ms
41,144 KB
testcase_32 AC 125 ms
41,192 KB
testcase_33 AC 125 ms
41,160 KB
testcase_34 AC 123 ms
41,292 KB
testcase_35 AC 112 ms
40,688 KB
testcase_36 AC 111 ms
40,228 KB
testcase_37 AC 120 ms
41,520 KB
testcase_38 AC 120 ms
41,392 KB
testcase_39 AC 124 ms
41,376 KB
testcase_40 AC 125 ms
41,236 KB
testcase_41 AC 120 ms
40,212 KB
testcase_42 AC 113 ms
40,568 KB
testcase_43 AC 126 ms
41,492 KB
testcase_44 AC 124 ms
41,416 KB
testcase_45 AC 116 ms
40,868 KB
testcase_46 AC 108 ms
40,124 KB
testcase_47 AC 125 ms
41,380 KB
testcase_48 AC 134 ms
41,252 KB
testcase_49 AC 126 ms
41,424 KB
testcase_50 AC 127 ms
41,592 KB
testcase_51 AC 128 ms
41,724 KB
testcase_52 AC 136 ms
41,524 KB
testcase_53 AC 127 ms
41,044 KB
testcase_54 AC 123 ms
41,480 KB
testcase_55 AC 125 ms
41,244 KB
testcase_56 AC 127 ms
41,652 KB
testcase_57 AC 121 ms
40,872 KB
testcase_58 AC 121 ms
40,932 KB
testcase_59 AC 128 ms
41,636 KB
testcase_60 AC 114 ms
40,572 KB
testcase_61 AC 120 ms
41,404 KB
testcase_62 WA -
testcase_63 AC 131 ms
41,396 KB
testcase_64 AC 118 ms
41,124 KB
testcase_65 AC 110 ms
40,184 KB
testcase_66 AC 126 ms
41,500 KB
testcase_67 AC 167 ms
40,324 KB
testcase_68 AC 168 ms
41,632 KB
testcase_69 AC 169 ms
41,504 KB
testcase_70 AC 165 ms
41,668 KB
testcase_71 AC 113 ms
40,308 KB
testcase_72 AC 113 ms
40,180 KB
testcase_73 AC 122 ms
41,460 KB
testcase_74 AC 124 ms
41,228 KB
testcase_75 AC 130 ms
41,184 KB
testcase_76 AC 121 ms
41,464 KB
testcase_77 AC 121 ms
41,672 KB
testcase_78 AC 127 ms
41,336 KB
testcase_79 AC 119 ms
41,288 KB
testcase_80 AC 108 ms
40,440 KB
testcase_81 AC 109 ms
40,152 KB
testcase_82 AC 109 ms
40,084 KB
testcase_83 AC 118 ms
41,328 KB
testcase_84 AC 121 ms
41,092 KB
testcase_85 AC 117 ms
41,244 KB
testcase_86 AC 116 ms
40,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package q462;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Test1 {


	private static BigInteger patternSum = new BigInteger("0");
	private static BigInteger RESULT_THEN_DIV = new BigInteger("1000000007");
	private static BigInteger BI_ONE = new BigInteger("1");

	public static void main(String[] args) {

		Scanner scaner = new Scanner(System.in);

		int n = scaner.nextInt();
		int k = scaner.nextInt();

		List<Long> numList = new ArrayList<Long>();

		for(int i = 0; i < k; i++){
			// 3つ目以降を格納
			numList.add(scaner.nextLong());
		}

		if(isEnabled(numList, k, n)){
			System.out.println(patternSum.remainder(RESULT_THEN_DIV));
		}else{
			System.out.println(0);
		}
	}

	/**
	 * 受け取った配列が有効か
	 * @param args 整数の文字列の配列 α1 ~ αk の配列
	 * @param arrLen 配列の長さ k
	 * @param n N
	 * @return true: 有効<br>false: 無効
	 */
	private static boolean isEnabled(List<Long> numList, int arrLen, int n){

		// ソートする
//		Arrays.sort(args);
//		System.out.println(Arrays.toString(args));
		Collections.sort(numList);

		long large = 0;
		long small = 0;

		// 差
		long rem;

		// ORした結果
		long orResult;

		boolean rtn = true;

		if(arrLen == 0){
			// すべてのパターン数を求める
			patternSum = findPatternsCount((long) Math.pow(2, n) - 1);
		}else{
			// 0と最初の要素の間は何通りあるか求める
			patternSum = findPatternsCount(numList.get(0));

			for(int i = 1; i < arrLen; i++){
				large = numList.get(i);
				small = numList.get(i - 1);

				rem = large - small;

				orResult = small | rem;

				// 1度立ったものが下がっていなければ一致するはず
				if(large == orResult){
					rtn = true;
					patternSum = patternSum.multiply(findPatternsCount(rem));
				}else{
					rtn = false;
				}
			}

			// 最後の要素と(2^n - 1)の間は何通りあるか求める
			rem = (long) Math.pow(2, n) - 1 - large;
			patternSum = patternSum.multiply(findPatternsCount(rem));
		}
		return rtn;
	}

	/**
	 * 差から2つの間のパターン数を求める
	 * @param rem 差
	 * @return 差の間は何通りか
	 */
	private static BigInteger findPatternsCount(long rem){

		int upBitSum = 0;
		BigInteger rtnFact = BI_ONE;
		if(rem != 0){
			// 2進数に変換
			String binStr = Long.toBinaryString(rem);

			int strLen = binStr.length();
			for(int i = 0; i < strLen; i++){
				// charをintに変換
				upBitSum += Character.getNumericValue(binStr.charAt(i));
			}

			rtnFact = getFact(new BigInteger(String.valueOf(upBitSum)));
		}
		return rtnFact;
	}

	/**
	 * 階乗を求める
	 * @param n 階乗を求めたい値
	 * @return 階乗
	 */
	private static BigInteger getFact(BigInteger n){

		if (n.equals(new BigInteger("0")))
            return BI_ONE;
        else {
        	BigInteger bi = new BigInteger(String.valueOf(n));
        	return bi.multiply(getFact(bi.subtract(BI_ONE)));
        }

	}
}
0