結果

問題 No.462 6日知らずのコンピュータ
ユーザー nksk38
提出日時 2017-07-31 16:56:52
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,423 bytes
コンパイル時間 742 ms
コンパイル使用メモリ 82,476 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-11 00:10:00
合計ジャッジ時間 2,707 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 64 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, string> pls;

ll mod = ll(1e9 + 7);

ll fuc(ll n) {
	ll res = 1;
	for (int i = 1; i <= n; i++) {
		res *= i;
		res %= mod;
	}
	return res;
}

ll numofbits(ll bits)
{
	bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
	bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
	bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
	bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
	return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}

int main()
{
	int n, k;
	ll a[100] = {0};
	ll ans;
	cin >> n >> k;
	
	for (int i = 0; i < k; i++) {
		cin >> a[i];
	}
	sort(a, a + k);

	for (int i = 0; i < k-1; i++) {
		if ((a[i + 1] | a[i]) != a[i + 1]) {
			cout << 0 << endl;
			return 0;
		}
	}

	if (k == 0) {
		ans = fuc(n);
		cout << ans << endl;
		return 0;
	}

	ans = fuc(numofbits(a[0]));
	for (int i = 1; i < k; i++) {
		ans *= fuc(numofbits(a[i]) - numofbits(a[i - 1]));
		ans %= mod;
	}
	ans *= fuc(numofbits(pow(2, n) - 1) - numofbits(a[k - 1]));
	ans %= mod;
	cout << ans << endl;
	return 0;
}
0