結果
問題 | No.1289 RNG and OR |
ユーザー | kopricky |
提出日時 | 2020-11-23 10:06:10 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 86 ms / 2,000 ms |
コード長 | 6,433 bytes |
コンパイル時間 | 1,678 ms |
コンパイル使用メモリ | 170,216 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-23 17:21:41 |
合計ジャッジ時間 | 2,913 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 3 ms
6,940 KB |
testcase_14 | AC | 3 ms
6,940 KB |
testcase_15 | AC | 4 ms
6,940 KB |
testcase_16 | AC | 7 ms
6,944 KB |
testcase_17 | AC | 13 ms
6,940 KB |
testcase_18 | AC | 22 ms
6,940 KB |
testcase_19 | AC | 43 ms
6,940 KB |
testcase_20 | AC | 86 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> #define ll long long #define INF 1000000005 #define MOD 998244353 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)(n);++i) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i) #define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i) #define each(a,b) for(const auto& (a): (b)) #define all(v) (v).begin(),(v).end() #define len(v) (int)(v).size() #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) #define cmx(x,y) x=max(x,y) #define cmn(x,y) x=min(x,y) #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)<<endl #define sar(a,n) {cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl;} using namespace std; template<typename S,typename T>auto&operator<<(ostream&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";} template<typename T>auto&operator<<(ostream&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;} template<typename S,typename T,typename U> auto&operator<<(ostream&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;} template<typename K,typename T>auto&operator<<(ostream&o,map<K,T>&m){for(auto&e:m)o<<e<<" ";return o;} template<typename T>auto&operator<<(ostream&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;} void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);} template<typename S,typename T,typename U> struct TRI{S fi;T se;U th;TRI(){}TRI(S f,T s,U t):fi(f),se(s),th(t){} bool operator<(const TRI&_)const{return(fi==_.fi)?((se==_.se)?(th<_.th):(se<_.se)):(fi<_.fi);}}; template<typename S,typename T,typename U> auto&operator<<(ostream&o,TRI<S,T,U>&t){return o<<"{"<<t.fi<<","<<t.se<<","<<t.th<<"}";} typedef pair<int, int> P; typedef pair<ll,ll> pll; typedef TRI<int, int, int> tri; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<P> vp; typedef vector<string> vs; const int MAX_N = 100005; template <unsigned int mod> class ModInt { private: unsigned int v; static unsigned int norm(const unsigned int& x){ return x < mod ? x : x - mod; } static ModInt make(const unsigned int& x){ ModInt m; return m.v = x, m; } static ModInt inv(const ModInt& x){ return make(inverse(x.v, mod)); } static unsigned int inverse(int a, int m){ int u[] = {a, 1, 0}, v[] = {m, 0, 1}, t; while(*v){ t = *u / *v; swap(u[0] -= t * v[0], v[0]), swap(u[1] -= t * v[1], v[1]), swap(u[2] -= t * v[2], v[2]); } return (u[1] % m + m) % m; } public: ModInt() : v{0}{} ModInt(const long long val) : v{norm(val % mod + mod)} {} ModInt(const ModInt<mod>& n) : v{n()} {} explicit operator bool() const noexcept { return v != 0; } bool operator!() const noexcept { return !static_cast<bool>(*this); } ModInt& operator=(const ModInt& n){ return v = n(), (*this); } ModInt& operator=(const long long val){ return v = norm(val % mod + mod), (*this); } ModInt operator+() const { return *this; } ModInt operator-() const { return v == 0 ? make(0) : make(mod - v); } ModInt operator+(const ModInt& val) const { return make(norm(v + val())); } ModInt operator-(const ModInt& val) const { return make(norm(v + mod - val())); } ModInt operator*(const ModInt& val) const { return make((long long)v * val() % mod); } ModInt operator/(const ModInt& val) const { return *this * inv(val); } ModInt& operator+=(const ModInt& val){ return *this = *this + val; } ModInt& operator-=(const ModInt& val){ return *this = *this - val; } ModInt& operator*=(const ModInt& val){ return *this = *this * val; } ModInt& operator/=(const ModInt& val){ return *this = *this / val; } ModInt operator+(const long long val) const { return ModInt{v + val}; } ModInt operator-(const long long val) const { return ModInt{v - val}; } ModInt operator*(const long long val) const { return ModInt{(long long)(v * (val % mod))}; } ModInt operator/(const long long val) const { return ModInt{(long long)v * inv(val)}; } ModInt& operator+=(const long long val){ return *this = *this + val; } ModInt& operator-=(const long long val){ return *this = *this - val; } ModInt& operator*=(const long long val){ return *this = *this * val; } ModInt& operator/=(const long long val){ return *this = *this / val; } bool operator==(const ModInt& val) const { return v == val.v; } bool operator!=(const ModInt& val) const { return !(*this == val); } bool operator==(const long long val) const { return v == norm(val % mod + mod); } bool operator!=(const long long val) const { return !(*this == val); } unsigned int operator()() const { return v; } friend ModInt operator+(const long long val, const ModInt& n) { return n + val; } friend ModInt operator-(const long long val, const ModInt& n) { return ModInt{val - n()}; } friend ModInt operator*(const long long val, const ModInt& n) { return n * val; } friend ModInt operator/(const long long val, const ModInt& n) { return ModInt{val} / n; } friend bool operator==(const long long val, const ModInt& n) { return n == val; } friend bool operator!=(const long long val, const ModInt& n) { return !(val == n); } friend istream& operator>>(istream& is, ModInt& n){ unsigned int v; return is >> v, n = v, is; } friend ostream& operator<<(ostream& os, const ModInt& n){ return (os << n()); } friend ModInt mod_pow(ModInt x, long long n){ ModInt ans = ((mod == 1) ? 0 : 1); while(n){ if(n & 1) ans *= x; x *= x, n >>= 1; } return ans; } }; using mod = ModInt<MOD>; void fast_zeta_transform(int n, vector<mod>& f) { for(int i = 0; i < n; ++i){ for(int j = 0; j < (1 << n); ++j){ if(j >> i & 1) f[j] += f[j ^ (1 << i)]; } } } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<mod> a(1<<n); int val, sm = 0; rep(i,(1<<n)){ cin >> val; a[i] = val, sm += val; } mod ism = (mod)1 / sm; rep(i,(1<<n)) a[i] *= ism; fast_zeta_transform(n, a); unsigned int mask = (1 << n) - 1; mod ans = 0; srep(i,1,(1<<n)){ if(__builtin_popcount(i) % 2) ans += 1 / (1 - a[i^mask]); else ans -= 1 / (1 - a[i^mask]); } cout << ans << "\n"; return 0; }