結果

問題 No.1482 Swap Many Permutations
ユーザー chocoruskchocorusk
提出日時 2021-04-16 22:03:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,353 bytes
コンパイル時間 3,634 ms
コンパイル使用メモリ 196,600 KB
実行使用メモリ 24,996 KB
最終ジャッジ日時 2023-09-16 00:44:02
合計ジャッジ時間 11,944 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<ll, int> P;
using mint=modint998244353;
ll powmod(ll a, ll k, ll MOD){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a, ll MOD){
    return powmod(a, MOD-2, MOD);
}
mint f[2000010], invf[2000010];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i;
    invf[n]=f[n].inv();
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1);
}
mint comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]*invf[x-y];
}
int b[100010], c[100010];
int s[100010];
int main()
{
    int n, m;
    cin>>n>>m;
    for(int i=0; i<n; i++) cin>>b[i]>>c[i];
    for(int i=0; i<n; i++){
        s[i+1]=s[i];
        if(m>=3){
            if(powmod(c[i], (m-1)/2, m)==m-1) s[i+1]^=1;
        }else{
            if(b[i]==1) s[i+1]^=1;
        }
    }
    mint l=mint(m)*mint(m-1)/mint(2);
    vector<mint> v(n+1), v0(n+1), v1(n+1);
    v[0]=1;
    for(int i=1; i<=n; i++){
        v[i]=v[i-1]*mint(l-i+1)/mint(i);
        //cout<<v[i].val()<<endl;
    }
    for(int i=0; i<=n; i++){
        if(i&1) v1[i]=v[i];
        else v0[i]=v[i];
    }
    auto c0=convolution(v0, v), c1=convolution(v1, v);
    fac(n);
    for(int i=1; i<=n; i++){
        if(i==1){
            cout<<1<<endl;
            continue;
        }
        if(i==2){
            if(m==2){
                if(s[i]==0) cout<<2<<endl;
                else cout<<0<<endl;
            }else{
                cout<<(l*2).val()<<endl;
            }
        }
        if(m==2){
            cout<<0<<endl;
        }else{
            if(s[i]==0) cout<<(c0[i]*f[i]).val()<<endl;
            else cout<<(c1[i]*f[i]).val()<<endl;
        }
    }
    return 0;
}
0