結果

問題 No.1958 Bit Game
ユーザー milanis48663220milanis48663220
提出日時 2022-05-27 21:43:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 445 ms / 2,000 ms
コード長 2,813 bytes
コンパイル時間 1,190 ms
コンパイル使用メモリ 126,708 KB
実行使用メモリ 16,288 KB
最終ジャッジ日時 2023-10-20 20:03:11
合計ジャッジ時間 11,757 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 422 ms
16,288 KB
testcase_01 AC 430 ms
16,288 KB
testcase_02 AC 434 ms
16,288 KB
testcase_03 AC 445 ms
16,288 KB
testcase_04 AC 434 ms
16,288 KB
testcase_05 AC 424 ms
16,288 KB
testcase_06 AC 436 ms
16,288 KB
testcase_07 AC 445 ms
16,288 KB
testcase_08 AC 436 ms
16,288 KB
testcase_09 AC 441 ms
16,288 KB
testcase_10 AC 139 ms
7,452 KB
testcase_11 AC 218 ms
9,856 KB
testcase_12 AC 200 ms
8,996 KB
testcase_13 AC 279 ms
12,072 KB
testcase_14 AC 258 ms
11,640 KB
testcase_15 AC 122 ms
6,164 KB
testcase_16 AC 68 ms
4,740 KB
testcase_17 AC 353 ms
13,792 KB
testcase_18 AC 276 ms
11,604 KB
testcase_19 AC 119 ms
6,220 KB
testcase_20 AC 362 ms
14,900 KB
testcase_21 AC 169 ms
7,656 KB
testcase_22 AC 205 ms
10,100 KB
testcase_23 AC 91 ms
5,796 KB
testcase_24 AC 377 ms
14,824 KB
testcase_25 AC 138 ms
7,252 KB
testcase_26 AC 329 ms
13,508 KB
testcase_27 AC 94 ms
5,428 KB
testcase_28 AC 360 ms
14,636 KB
testcase_29 AC 191 ms
9,500 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/modint>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

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

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using mint = atcoder::modint998244353;

ostream& operator<<(ostream& os, const mint& m){
    os << m.val();
    return os;
}

int nx(int cur, int s){
    if(cur == 1 || (s&2) > 0){
        cur = 1;
    }
    cur &= s;
    return cur;
}

mint sub_solve(mint p, mint q, int n){
    auto dp = vec2d(n+1, 2, mint(0));
    dp[0][0] = 1;
    vector<mint> proba(4);
    proba[0] = (mint(1)-mint(p))*(mint(1)-mint(q));
    proba[1] = (mint(1)-mint(p))*mint(q);
    proba[2] = mint(p)*(mint(1)-mint(q));
    proba[3] = mint(p)*mint(q);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 2; j++){
            for(int s = 0; s < 4; s++){
                dp[i+1][nx(j, s)] += dp[i][j]*proba[s];
            }
        }
    }
    return dp[n][1];
}

mint pow(mint a, ll n) {
    assert(n >= 0);
	mint ans = 1;
    while (n > 0) {
        if (n&1) ans = ans*a;
        a = a*a;
        n >>= 1;
    }
	return ans;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, x, y; cin >> n >> x >> y;
    vector<int> a(x), b(y);
    for(int i = 0; i < x; i++) cin >> a[i];
    for(int i = 0; i < y; i++) cin >> b[i];
    mint x_inv = mint(x).inv();
    mint y_inv = mint(y).inv();
    mint ans = 0;
    mint pw = pow(mint(x)*mint(y), n);
    for(int i = 0; i < 18; i++){
        mint p = 0, q = 0;
        for(int j = 0; j < x; j++) {
            if(a[j]&(1<<i)) p += x_inv;
        }
        for(int j = 0; j < y; j++) {
            if(b[j]&(1<<i)) q += y_inv;
        }
        ans += sub_solve(p, q, n)*(1<<i);
    }
    ans *= pw;
    cout << ans << endl;
}
0