結果

問題 No.462 6日知らずのコンピュータ
ユーザー 👑 jupirojupiro
提出日時 2020-02-10 13:52:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 370 ms / 2,000 ms
コード長 2,876 bytes
コンパイル時間 1,847 ms
コンパイル使用メモリ 121,336 KB
実行使用メモリ 123,228 KB
最終ジャッジ日時 2024-04-08 12:58:52
合計ジャッジ時間 34,832 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 338 ms
123,228 KB
testcase_01 AC 363 ms
123,228 KB
testcase_02 AC 356 ms
123,228 KB
testcase_03 AC 357 ms
123,228 KB
testcase_04 AC 346 ms
123,228 KB
testcase_05 AC 370 ms
123,228 KB
testcase_06 AC 344 ms
123,228 KB
testcase_07 AC 345 ms
123,228 KB
testcase_08 AC 343 ms
123,228 KB
testcase_09 AC 349 ms
123,228 KB
testcase_10 AC 345 ms
123,228 KB
testcase_11 AC 341 ms
123,228 KB
testcase_12 AC 367 ms
123,228 KB
testcase_13 AC 333 ms
123,228 KB
testcase_14 AC 341 ms
123,228 KB
testcase_15 AC 332 ms
123,228 KB
testcase_16 AC 349 ms
123,228 KB
testcase_17 AC 348 ms
123,228 KB
testcase_18 AC 328 ms
123,228 KB
testcase_19 AC 328 ms
123,228 KB
testcase_20 AC 354 ms
123,228 KB
testcase_21 AC 332 ms
123,228 KB
testcase_22 AC 347 ms
123,228 KB
testcase_23 AC 330 ms
123,228 KB
testcase_24 AC 327 ms
123,228 KB
testcase_25 AC 354 ms
123,228 KB
testcase_26 AC 342 ms
123,228 KB
testcase_27 AC 340 ms
123,228 KB
testcase_28 AC 336 ms
123,228 KB
testcase_29 AC 341 ms
123,228 KB
testcase_30 AC 350 ms
123,228 KB
testcase_31 AC 345 ms
123,228 KB
testcase_32 AC 348 ms
123,228 KB
testcase_33 AC 364 ms
123,228 KB
testcase_34 AC 340 ms
123,228 KB
testcase_35 AC 341 ms
123,228 KB
testcase_36 AC 330 ms
123,228 KB
testcase_37 AC 333 ms
123,228 KB
testcase_38 AC 341 ms
123,228 KB
testcase_39 AC 342 ms
123,228 KB
testcase_40 AC 354 ms
123,228 KB
testcase_41 AC 344 ms
123,228 KB
testcase_42 AC 362 ms
123,228 KB
testcase_43 AC 365 ms
123,228 KB
testcase_44 AC 347 ms
123,228 KB
testcase_45 AC 351 ms
123,228 KB
testcase_46 AC 350 ms
123,228 KB
testcase_47 AC 347 ms
123,228 KB
testcase_48 AC 337 ms
123,228 KB
testcase_49 AC 332 ms
123,228 KB
testcase_50 AC 330 ms
123,228 KB
testcase_51 AC 346 ms
123,228 KB
testcase_52 AC 334 ms
123,228 KB
testcase_53 AC 356 ms
123,228 KB
testcase_54 AC 353 ms
123,228 KB
testcase_55 AC 352 ms
123,228 KB
testcase_56 AC 351 ms
123,228 KB
testcase_57 AC 336 ms
123,228 KB
testcase_58 AC 352 ms
123,228 KB
testcase_59 AC 335 ms
123,228 KB
testcase_60 AC 329 ms
123,228 KB
testcase_61 AC 332 ms
123,228 KB
testcase_62 AC 325 ms
123,228 KB
testcase_63 AC 319 ms
123,228 KB
testcase_64 AC 331 ms
123,228 KB
testcase_65 AC 330 ms
123,228 KB
testcase_66 AC 316 ms
123,228 KB
testcase_67 AC 322 ms
123,228 KB
testcase_68 AC 326 ms
123,228 KB
testcase_69 AC 325 ms
123,228 KB
testcase_70 AC 322 ms
123,228 KB
testcase_71 AC 325 ms
123,228 KB
testcase_72 AC 320 ms
123,228 KB
testcase_73 AC 326 ms
123,228 KB
testcase_74 AC 327 ms
123,228 KB
testcase_75 AC 324 ms
123,228 KB
testcase_76 AC 323 ms
123,228 KB
testcase_77 AC 327 ms
123,228 KB
testcase_78 AC 321 ms
123,228 KB
testcase_79 AC 326 ms
123,228 KB
testcase_80 AC 325 ms
123,228 KB
testcase_81 AC 326 ms
123,228 KB
testcase_82 AC 319 ms
123,228 KB
testcase_83 AC 317 ms
123,228 KB
testcase_84 AC 314 ms
123,228 KB
testcase_85 AC 321 ms
123,228 KB
testcase_86 AC 330 ms
123,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

mint COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return mint(fac[n] * (finv[k] * finv[n - k] % mod) % mod);
}

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	COMinit();
	ll n, k; scanf("%lld %lld", &n, &k);
	vector<ll> a(k + 2);
	a[0] = 0;
	for (ll i = 0; i < k; i++) scanf("%lld", &a[i]);
	a[k + 1] = (1LL << n) - 1;
	sort(a.begin(), a.end());
	k += 2;
	vector<bool> used(n);
	vector<ll> cnt(k + 2);
	for (ll i = 0; i < k; i++) {
		for (ll j = 0; j < n; j++) {
			if (used[j] && !(a[i] >> j & 1)) {
				puts("0");
				return 0;
			}
			if (a[i] >> j & 1) {
				used[j] = true;
				cnt[i]++;
			}
		}
	}
	mint res = 1;

	for (ll i = 0; i < k - 1; i++) {
		//cout << cnt[i + 1] << " " << cnt[i] << endl;
		res *= mint(fac[cnt[i + 1] - cnt[i]]);
	}
	cout << res.x << endl;
	return 0;
}
0