結果

問題 No.462 6日知らずのコンピュータ
ユーザー tamago324_padtamago324_pad
提出日時 2016-12-25 03:54:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 3,140 bytes
コンパイル時間 3,546 ms
コンパイル使用メモリ 76,364 KB
実行使用メモリ 58,228 KB
最終ジャッジ日時 2023-08-21 08:53:37
合計ジャッジ時間 17,581 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,496 KB
testcase_01 AC 123 ms
56,220 KB
testcase_02 AC 137 ms
56,304 KB
testcase_03 AC 140 ms
58,228 KB
testcase_04 AC 127 ms
56,252 KB
testcase_05 AC 128 ms
56,132 KB
testcase_06 AC 123 ms
56,180 KB
testcase_07 AC 126 ms
56,008 KB
testcase_08 AC 125 ms
56,140 KB
testcase_09 AC 125 ms
56,364 KB
testcase_10 AC 126 ms
55,856 KB
testcase_11 AC 124 ms
55,948 KB
testcase_12 AC 126 ms
56,096 KB
testcase_13 AC 128 ms
55,936 KB
testcase_14 AC 133 ms
56,388 KB
testcase_15 AC 125 ms
56,624 KB
testcase_16 AC 128 ms
55,860 KB
testcase_17 AC 130 ms
55,892 KB
testcase_18 AC 125 ms
55,988 KB
testcase_19 AC 125 ms
56,124 KB
testcase_20 AC 126 ms
55,940 KB
testcase_21 AC 129 ms
56,216 KB
testcase_22 AC 128 ms
55,856 KB
testcase_23 AC 133 ms
56,296 KB
testcase_24 AC 125 ms
56,212 KB
testcase_25 AC 137 ms
56,244 KB
testcase_26 AC 130 ms
55,912 KB
testcase_27 AC 125 ms
55,820 KB
testcase_28 AC 124 ms
55,968 KB
testcase_29 AC 131 ms
56,332 KB
testcase_30 AC 125 ms
55,880 KB
testcase_31 AC 126 ms
56,384 KB
testcase_32 AC 123 ms
55,712 KB
testcase_33 AC 125 ms
56,336 KB
testcase_34 AC 125 ms
56,344 KB
testcase_35 AC 125 ms
55,876 KB
testcase_36 AC 129 ms
55,572 KB
testcase_37 AC 125 ms
55,832 KB
testcase_38 AC 122 ms
56,024 KB
testcase_39 AC 126 ms
56,136 KB
testcase_40 AC 129 ms
56,228 KB
testcase_41 AC 133 ms
56,780 KB
testcase_42 AC 128 ms
56,240 KB
testcase_43 AC 129 ms
55,852 KB
testcase_44 AC 129 ms
56,164 KB
testcase_45 AC 122 ms
55,940 KB
testcase_46 AC 128 ms
55,904 KB
testcase_47 AC 131 ms
55,692 KB
testcase_48 AC 131 ms
56,024 KB
testcase_49 AC 125 ms
56,396 KB
testcase_50 AC 126 ms
55,960 KB
testcase_51 AC 123 ms
55,980 KB
testcase_52 AC 133 ms
55,804 KB
testcase_53 AC 125 ms
56,288 KB
testcase_54 AC 123 ms
56,176 KB
testcase_55 AC 128 ms
56,276 KB
testcase_56 AC 132 ms
55,720 KB
testcase_57 AC 132 ms
56,208 KB
testcase_58 AC 128 ms
55,572 KB
testcase_59 AC 135 ms
55,812 KB
testcase_60 AC 134 ms
56,200 KB
testcase_61 AC 124 ms
56,344 KB
testcase_62 AC 124 ms
56,180 KB
testcase_63 AC 129 ms
56,008 KB
testcase_64 AC 124 ms
56,072 KB
testcase_65 AC 124 ms
55,988 KB
testcase_66 AC 131 ms
55,864 KB
testcase_67 AC 132 ms
56,200 KB
testcase_68 AC 131 ms
56,240 KB
testcase_69 AC 135 ms
56,308 KB
testcase_70 AC 129 ms
57,968 KB
testcase_71 AC 133 ms
55,980 KB
testcase_72 AC 127 ms
55,892 KB
testcase_73 AC 130 ms
56,024 KB
testcase_74 AC 127 ms
56,044 KB
testcase_75 AC 135 ms
56,144 KB
testcase_76 AC 126 ms
55,696 KB
testcase_77 AC 130 ms
56,092 KB
testcase_78 AC 133 ms
55,956 KB
testcase_79 AC 123 ms
55,960 KB
testcase_80 AC 123 ms
55,980 KB
testcase_81 AC 122 ms
56,484 KB
testcase_82 AC 126 ms
55,936 KB
testcase_83 AC 125 ms
55,952 KB
testcase_84 AC 124 ms
56,156 KB
testcase_85 AC 125 ms
55,960 KB
testcase_86 AC 125 ms
56,172 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));

			if(arrLen == 1){
				large = numList.get(0);
			}else{
				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