結果

問題 No.2082 AND OR XOR
ユーザー StstoneStstone
提出日時 2022-10-18 17:43:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 2,408 bytes
コンパイル時間 3,323 ms
コンパイル使用メモリ 226,704 KB
実行使用メモリ 7,588 KB
最終ジャッジ日時 2023-09-11 10:24:20
合計ジャッジ時間 5,043 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,344 KB
testcase_01 AC 4 ms
7,292 KB
testcase_02 AC 5 ms
7,300 KB
testcase_03 AC 15 ms
7,288 KB
testcase_04 AC 8 ms
7,412 KB
testcase_05 AC 10 ms
7,356 KB
testcase_06 AC 14 ms
7,360 KB
testcase_07 AC 12 ms
7,288 KB
testcase_08 AC 9 ms
7,264 KB
testcase_09 AC 7 ms
7,316 KB
testcase_10 AC 12 ms
7,256 KB
testcase_11 AC 9 ms
7,488 KB
testcase_12 AC 18 ms
7,312 KB
testcase_13 AC 9 ms
7,352 KB
testcase_14 AC 9 ms
7,540 KB
testcase_15 AC 11 ms
7,292 KB
testcase_16 AC 14 ms
7,284 KB
testcase_17 AC 13 ms
7,572 KB
testcase_18 AC 6 ms
7,372 KB
testcase_19 AC 15 ms
7,364 KB
testcase_20 AC 10 ms
7,360 KB
testcase_21 AC 12 ms
7,264 KB
testcase_22 AC 10 ms
7,252 KB
testcase_23 AC 15 ms
7,416 KB
testcase_24 AC 16 ms
7,288 KB
testcase_25 AC 16 ms
7,356 KB
testcase_26 AC 8 ms
7,296 KB
testcase_27 AC 10 ms
7,420 KB
testcase_28 AC 17 ms
7,476 KB
testcase_29 AC 17 ms
7,364 KB
testcase_30 AC 16 ms
7,288 KB
testcase_31 AC 17 ms
7,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define pb push_back
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define bug(x) cerr << (x) << '\n'
#define yn(x) cout << (x==1?"Yes\n":"No\n")
#define PI 3.14159265358979323
#define Ststone ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const ll max_n=2e5+20,max_int=2147483647,mod1=1e9+7,mod2=998244353;
const bool online = 0;
ll dx[8] = {1,0,0,-1,1,1,-1,-1};
ll dy[8] = {0,1,-1,0,1,-1,1,-1};
ll t,n,q,m,a,b,c,d,e,dp[5010][10][10],ans=0;
vector<ll> v,v1,v2,v3,v4;
char cc;
str s;

ll f(ll x,ll y){
    return ((a*(x&y))+(b*(x|y))+(c*(x^y)))%4;
}

void solve(){
    cin >> n;
    cin >> a >> b >> c;
    for(ll goal=0;goal<4;goal++){
        for(ll i=0;i<5010;i++){
            for(ll j=0;j<4;j++){
                for(ll k=0;k<4;k++){
                    dp[i][j][k] = 0;
                }
            }
        }
        for(ll i=0;i<4;i++){
            for(ll j=0;j<4;j++){
                if(f(i,j)==goal)
                    dp[1][i][j] = 1;
            }
        }
        for(ll i=2;i<n;i++){
            for(ll s1=0;s1<4;s1++){
                for(ll s2=0;s2<4;s2++){
                    for(ll r1=0;r1<4;r1++){
                        for(ll r2=0;r2<4;r2++){
                            for(ll ak=0;ak<4;ak++){
                                if(f(s1,ak)==s2&&f(r2,ak)==r1){
                                    dp[i][s2][r2] += dp[i-1][s1][r1];
                                    dp[i][s2][r2] %= mod2;
                                }
                            }
                        }
                    }
                }
            }
        }
        for(ll i=0;i<4;i++){
            for(ll j=0;j<4;j++){
                if(f(i,j)==goal)
                    ans +=  dp[n-1][i][j];
                    ans %= mod2;
            }
        }
    }
    cout << ans << '\n';
}

int main(){
    Ststone;
    if(online){
        #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #else
        #endif
    }
    //cin >> t;
    t = 1;
    for(ll i=1;i<=t;i++){
        //cout << "Case #"<<i<<": ";
        solve();
    }
}


/*

*/
0