結果

問題 No.641 Team Contest Estimation
ユーザー mamekinmamekin
提出日時 2018-01-27 16:55:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 3,007 bytes
コンパイル時間 859 ms
コンパイル使用メモリ 105,128 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 09:57:10
合計ジャッジ時間 1,894 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 68 ms
4,376 KB
testcase_06 AC 68 ms
4,380 KB
testcase_07 AC 68 ms
4,376 KB
testcase_08 AC 68 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0