結果
問題 | No.462 6日知らずのコンピュータ |
ユーザー |
|
提出日時 | 2016-12-13 06:05:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,352 bytes |
コンパイル時間 | 1,903 ms |
コンパイル使用メモリ | 176,912 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-30 00:37:44 |
合計ジャッジ時間 | 4,025 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 84 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr) #define all(x) (x).begin(),(x).end() #define pb push_back #define fi first #define se second const ll mod=1e9+7; typedef pair<int,ll> P; inline ll fact(int n) { ll ret=1; for(ll i=2; i<=n; ++i) (ret*=i)%=mod; return ret; } inline bool canmove(ll from, ll to) { rep(i,63) { if((from>>i&1LL) && !(to>>i&1LL)) return false; } return true; } ll solve() { int n,k; scanf(" %d %d", &n, &k); int ct[61]={}; vector<P> s; s.pb(P(0,0)); s.pb(P(n,(1LL<<n)-1)); rep(i,k) { ll t; scanf(" %lld", &t); ++ct[__builtin_popcountll(t)]; s.pb(P(__builtin_popcountll(t),t)); } if(k==0) return fact(n); rep(i,61) if(ct[i]>1) return 0; sort(all(s)); s.erase(unique(all(s)),s.end()); k=s.size(); vector<ll> a(k); rep(i,k) a[i]=s[i].se; // rep(i,k) printf("a[%d] = %lld\n", i,a[i]); ll ret=1; rep(i,k-1) { if(!canmove(a[i],a[i+1])) return 0; (ret*=fact(__builtin_popcountll(a[i+1])-__builtin_popcountll(a[i])))%=mod; } return ret; } int main() { cout << solve() << endl; return 0; }