結果

問題 No.2082 AND OR XOR
ユーザー milanis48663220milanis48663220
提出日時 2022-09-26 23:45:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,473 ms / 2,000 ms
コード長 3,307 bytes
コンパイル時間 1,612 ms
コンパイル使用メモリ 127,096 KB
実行使用メモリ 23,636 KB
最終ジャッジ日時 2023-08-24 03:18:22
合計ジャッジ時間 29,688 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
23,332 KB
testcase_01 AC 9 ms
23,636 KB
testcase_02 AC 38 ms
23,364 KB
testcase_03 AC 1,207 ms
23,368 KB
testcase_04 AC 364 ms
23,344 KB
testcase_05 AC 720 ms
23,336 KB
testcase_06 AC 1,044 ms
23,588 KB
testcase_07 AC 801 ms
23,364 KB
testcase_08 AC 563 ms
23,340 KB
testcase_09 AC 306 ms
23,340 KB
testcase_10 AC 805 ms
23,360 KB
testcase_11 AC 568 ms
23,404 KB
testcase_12 AC 1,453 ms
23,344 KB
testcase_13 AC 641 ms
23,336 KB
testcase_14 AC 550 ms
23,424 KB
testcase_15 AC 849 ms
23,360 KB
testcase_16 AC 1,158 ms
23,352 KB
testcase_17 AC 936 ms
23,400 KB
testcase_18 AC 205 ms
23,400 KB
testcase_19 AC 1,144 ms
23,380 KB
testcase_20 AC 709 ms
23,520 KB
testcase_21 AC 974 ms
23,348 KB
testcase_22 AC 809 ms
23,404 KB
testcase_23 AC 1,285 ms
23,460 KB
testcase_24 AC 1,245 ms
23,328 KB
testcase_25 AC 1,300 ms
23,328 KB
testcase_26 AC 451 ms
23,332 KB
testcase_27 AC 650 ms
23,416 KB
testcase_28 AC 1,460 ms
23,328 KB
testcase_29 AC 1,456 ms
23,332 KB
testcase_30 AC 1,473 ms
23,636 KB
testcase_31 AC 1,453 ms
23,544 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;
}

using F = vector<vector<int>>;
using S = vector<F>;

mint dp[5005][4][4][4][4][4];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, a, b, c; cin >> n >> a >> b >> c;
    vector<vector<int>> f(4, vector<int>(4));
    for(int x = 0; x < 4; x++){
        vector<int> v(4);
        for(int y = 0; y < 4; y++){
            v[y] = (a*(x&y) + b*(x|y) + c*(x^y))%4;
        }
        f[x] = v;
        dp[0][x][v[0]][v[1]][v[2]][v[3]]++;
    }
    auto composition = [&](vector<int> f, vector<int> g){
        vector<int> ans(4);
        for(int i = 0; i < 4; i++) ans[i] = f[g[i]];
        return ans;
    };
    for(int i = 1; i < n-1; i++){
        for(int x = 0; x < 4; x++){
            for(int f0 = 0; f0 < 4; f0++){
                for(int f1 = 0; f1 < 4; f1++){
                    for(int f2 = 0; f2 < 4; f2++){
                        for(int f3 = 0; f3 < 4; f3++){
                            for(int y = 0; y < 4; y++){
                                int z = (a*(x&y) + b*(x|y) + c*(x^y))%4;
                                auto ff = composition({f0, f1, f2, f3}, f[y]);
                                dp[i][z][ff[0]][ff[1]][ff[2]][ff[3]] += dp[i-1][x][f0][f1][f2][f3];
                            }
                        }
                    }
                }
            }
        }
    }
    mint ans = 0;
    for(int x = 0; x < 4; x++){
        for(int f0 = 0; f0 < 4; f0++){
            for(int f1 = 0; f1 < 4; f1++){
                for(int f2 = 0; f2 < 4; f2++){
                    for(int f3 = 0; f3 < 4; f3++){
                        for(int y = 0; y < 4; y++){
                            int z = (a*(x&y) + b*(x|y) + c*(x^y))%4;
                            vector<int> f = {f0, f1, f2, f3};
                            if(z == f[y]) ans += dp[n-2][x][f0][f1][f2][f3];
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}
0