結果

問題 No.2428 Returning Shuffle
ユーザー porkleoiporkleoi
提出日時 2023-08-18 22:13:11
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,501 bytes
コンパイル時間 2,892 ms
コンパイル使用メモリ 248,708 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2024-05-06 04:21:34
合計ジャッジ時間 7,377 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 344 ms
18,816 KB
testcase_25 AC 340 ms
18,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i <= (ll)(n); i++)
#define rep3(i, s, n, d) for (ll i = s; i <= (ll)(n); i += d)
#define rep4(i, s, n, d) for (ll i = s; i >= (ll)(n); i += d)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<bool> vb;
typedef vector<vd> vvb;
typedef vector<vvd> vvvb;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> pqi;
typedef priority_queue<vi, vector<vi>, greater<vi>> pqvi;
typedef priority_queue<vll, vector<vll>, greater<vll>> pqvll;
typedef priority_queue<int, vector<int>, less<int>> rpqi;
#define yes(ans) if(ans)cout << "yes"<< endl; else cout << "no" << endl
#define Yes(ans) if(ans)cout << "Yes"<< endl; else cout << "No" << endl
#define YES(ans) if(ans)cout << "YES"<< endl ;else cout << "NO" << endl
#define all1(x) x.begin(),x.end()
#define all2(x) x.rbegin(), x.rend()
#define so(x) sort(all1(x))
#define re(x) reverse(all1(x))
#define rso(x) sort(all2(x))
#define vco(x, a) count(all1(x), a)
#define per(x) next_permutation(all1(x))
#define iINF 2147483647
#define llINF 9223372036854775807
#define mod 998244353
#define mod2 1000000007

int main(){
    ll n, m; cin >> n >> m;
    vll vec(n); rep(i, n) vec[i] = i;
    rep(i, m){
        ll t; cin >> t;
        vll rol(t);
        rep(j, t){
            cin >> rol[j];
            rol[j]--;
        }
        re(rol);
        ll x = vec[rol[0]];
        rep(j, t-1) vec[rol[j]] = vec[rol[j+1]];
        vec[rol[t-1]] = x;
    }
    //rep(i, n) cout << vec[i]+1 << ' ';
    ll ans = 1;
    vi che(n);
    rep(i, n){
        if(che[i]==1) continue;
        ll x = vec[i], sum = 0;
        while(true){
            sum++;
            che[x] = 1;
            if(vec[x]==i) break;
            x = vec[x];
        }
        if(sum==1) continue;
        ans *= sum+1;
        ans %= mod;
        //cout << sum << ' ';
    }
    //cout << endl;
    cout << ans << endl;
}
0