結果

問題 No.462 6日知らずのコンピュータ
ユーザー matsukin1111
提出日時 2019-04-29 10:45:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,607 bytes
コンパイル時間 1,135 ms
コンパイル使用メモリ 101,944 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-24 00:34:47
合計ジャッジ時間 3,734 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 84
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };

ll getbit(ll n) {
	ll ret = 0;
	while (n > 0) {
		ret += n % 2;
		n /= 2;
	}
	return ret;
}

ll po(ll a,ll b) {
	ll ret = 1;
	rep(i,0,b) {
		ret *= a;
	}
	return ret;
}

ll check(ll a, ll b) {
	while (a > 0 || b > 0) {
		ll m1 = a % 2;
		ll m2 = b % 2;
		if (m2 == 0 && m1 == 1)return false;
		a /= 2;
		b /= 2;
	}
	return true;
}

ll fac(ll a) {
	ll ret = 1;
	for (ll i = 1; i <= a; i++) {
		ret *= i;
		ret %= MOD;
	}
	return ret % MOD;
}

int main() {
	ll n, k;
	cin >> n >> k;

	vector<pair<ll,ll>>a;
	rep(i, 0, k) {
		ll temp;
		cin >> temp;
		a.pb({ getbit(temp),temp });
	}
	a.pb({0,0});
	a.pb({ n,po(2,n) - 1 });
	sort(all(a));

	ll ans = 1;
	rep(i,0,a.size()-1) {
		if (check(a[i].second,a[i+1].second)) {
			ans *= fac(a[i+1].first-a[i].first);
			ans %= MOD;
		}
		else {
			ans = 0;
			break;
		}
	}

	cout << ans%MOD << endl;


	return 0;
}
0