結果
問題 | No.641 Team Contest Estimation |
ユーザー |
|
提出日時 | 2018-01-27 16:55:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 73 ms / 2,000 ms |
コード長 | 3,007 bytes |
コンパイル時間 | 1,008 ms |
コンパイル使用メモリ | 105,900 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-29 06:53:00 |
合計ジャッジ時間 | 1,994 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 |
ソースコード
#define _USE_MATH_DEFINES#include <cstdio>#include <iostream>#include <sstream>#include <fstream>#include <iomanip>#include <algorithm>#include <cmath>#include <complex>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <set>#include <map>#include <bitset>#include <numeric>#include <limits>#include <climits>#include <cfloat>#include <functional>#include <iterator>using namespace std;template <class T1>class Operators{public:template <class T2>const T1 operator+(const T2& right) const{T1 ans = static_cast<const T1&>( *this );ans += right;return ans;}template <class T2>const T1 operator-(const T2& right) const{T1 ans = static_cast<const T1&>( *this );ans -= right;return ans;}template <class T2>const T1 operator*(const T2& right) const{T1 ans = static_cast<const T1&>( *this );ans *= right;return ans;}template <class T2>const T1 operator/(const T2& right) const{T1 ans = static_cast<const T1&>( *this );ans /= right;return ans;}bool operator!=(const T1& right) const{const T1& left = static_cast<const T1&>( *this );return !(left == right);}};class Mod : public Operators<Mod>{private:static const int MOD = 1000000009;long long a;public:Mod(){a = 0;}Mod(long long x){a = (x % MOD + MOD) % MOD;}Mod& operator+=(const Mod& x){a = (a + x.a) % MOD;return *this;}Mod& operator-=(const Mod& x){a = (a - x.a + MOD) % MOD;return *this;}Mod& operator*=(const Mod& x){a = (a * x.a) % MOD;return *this;}Mod& operator/=(const Mod& x){ // フェルマーの小定理、MODが素数である場合のみ有効int b = MOD - 2;long long c = x.a;while(b > 0){if(b & 1){a *= c;a %= MOD;}c *= c;c %= MOD;b >>= 1;}return *this;}bool operator==(const Mod& x) const{return a == x.a;}long long getValue(){return a;}};int main(){int n, k;cin >> n >> k;vector<long long> a(n);for(int i=0; i<n; ++i)cin >> a[i];vector<Mod> ans(2, 0);for(int i=0; i<k; ++i){int cnt = 0;for(int j=0; j<n; ++j){if(a[j] & (1LL << i))++ cnt;}Mod mu = 1LL << i;mu *= n;mu /= 2;ans[0] += mu * (1LL << k);Mod x = cnt;Mod y = n - cnt;x *= 1LL << i;y *= 1LL << i;Mod var = (x - mu) * (x - mu) + (y - mu) * (y - mu);var /= 2;ans[1] += var * (1LL << k) * (1LL << k);}cout << ans[0].getValue() << endl << ans[1].getValue() << endl;return 0;}