結果

問題 No.1482 Swap Many Permutations
ユーザー chocoruskchocorusk
提出日時 2021-04-16 22:06:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 2,298 bytes
コンパイル時間 3,860 ms
コンパイル使用メモリ 196,672 KB
実行使用メモリ 25,004 KB
最終ジャッジ日時 2023-09-16 00:47:40
合計ジャッジ時間 13,330 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
19,016 KB
testcase_01 AC 6 ms
19,168 KB
testcase_02 AC 6 ms
19,088 KB
testcase_03 AC 7 ms
18,956 KB
testcase_04 AC 6 ms
19,040 KB
testcase_05 AC 6 ms
19,080 KB
testcase_06 AC 6 ms
19,084 KB
testcase_07 AC 7 ms
19,028 KB
testcase_08 AC 6 ms
19,088 KB
testcase_09 AC 6 ms
18,956 KB
testcase_10 AC 6 ms
18,976 KB
testcase_11 AC 7 ms
18,964 KB
testcase_12 AC 121 ms
21,724 KB
testcase_13 AC 118 ms
21,716 KB
testcase_14 AC 251 ms
24,584 KB
testcase_15 AC 207 ms
24,268 KB
testcase_16 AC 52 ms
20,056 KB
testcase_17 AC 198 ms
23,956 KB
testcase_18 AC 63 ms
20,288 KB
testcase_19 AC 104 ms
21,160 KB
testcase_20 AC 212 ms
24,340 KB
testcase_21 AC 235 ms
24,564 KB
testcase_22 AC 267 ms
24,888 KB
testcase_23 AC 266 ms
24,748 KB
testcase_24 AC 263 ms
24,924 KB
testcase_25 AC 267 ms
24,840 KB
testcase_26 AC 267 ms
24,844 KB
testcase_27 AC 268 ms
24,832 KB
testcase_28 AC 265 ms
24,752 KB
testcase_29 AC 261 ms
24,784 KB
testcase_30 AC 264 ms
24,772 KB
testcase_31 AC 268 ms
24,832 KB
testcase_32 AC 264 ms
24,896 KB
testcase_33 AC 267 ms
25,004 KB
testcase_34 AC 265 ms
24,888 KB
testcase_35 AC 266 ms
24,784 KB
testcase_36 AC 267 ms
24,840 KB
testcase_37 AC 6 ms
18,964 KB
testcase_38 AC 6 ms
19,088 KB
testcase_39 AC 6 ms
18,972 KB
testcase_40 AC 6 ms
19,032 KB
testcase_41 AC 6 ms
19,184 KB
testcase_42 AC 110 ms
21,888 KB
testcase_43 AC 115 ms
21,856 KB
testcase_44 AC 110 ms
21,812 KB
testcase_45 AC 127 ms
22,148 KB
testcase_46 AC 156 ms
23,832 KB
権限があれば一括ダウンロードができます

ソースコード

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(b[0]==b[1] && c[0]==c[1]) cout<<0<<endl;
            else cout<<(l*2).val()<<endl;
            continue;
        }
        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