結果
| 問題 |
No.2082 AND OR XOR
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2022-09-26 23:45:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,508 ms / 2,000 ms |
| コード長 | 3,307 bytes |
| コンパイル時間 | 1,218 ms |
| コンパイル使用メモリ | 125,720 KB |
| 最終ジャッジ日時 | 2025-02-07 16:31:24 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
#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;
}
milanis48663220