結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
19,236 KB
testcase_01 AC 6 ms
19,084 KB
testcase_02 AC 6 ms
19,032 KB
testcase_03 AC 6 ms
19,092 KB
testcase_04 AC 6 ms
19,088 KB
testcase_05 AC 6 ms
19,228 KB
testcase_06 AC 6 ms
19,092 KB
testcase_07 AC 5 ms
19,048 KB
testcase_08 AC 6 ms
19,104 KB
testcase_09 AC 6 ms
19,148 KB
testcase_10 AC 6 ms
19,312 KB
testcase_11 AC 6 ms
19,136 KB
testcase_12 AC 119 ms
21,860 KB
testcase_13 AC 117 ms
21,768 KB
testcase_14 AC 249 ms
24,704 KB
testcase_15 AC 207 ms
24,336 KB
testcase_16 AC 52 ms
19,920 KB
testcase_17 AC 199 ms
24,044 KB
testcase_18 AC 64 ms
20,376 KB
testcase_19 AC 104 ms
21,408 KB
testcase_20 AC 211 ms
24,488 KB
testcase_21 AC 232 ms
24,504 KB
testcase_22 AC 265 ms
24,792 KB
testcase_23 AC 265 ms
24,844 KB
testcase_24 AC 265 ms
24,792 KB
testcase_25 AC 266 ms
24,836 KB
testcase_26 AC 267 ms
24,836 KB
testcase_27 AC 265 ms
24,844 KB
testcase_28 AC 264 ms
24,992 KB
testcase_29 AC 266 ms
24,960 KB
testcase_30 AC 264 ms
24,916 KB
testcase_31 AC 265 ms
24,840 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 6 ms
19,044 KB
testcase_38 AC 6 ms
19,040 KB
testcase_39 AC 6 ms
19,032 KB
testcase_40 AC 6 ms
19,088 KB
testcase_41 AC 6 ms
19,228 KB
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;
            }
            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