結果

問題 No.2428 Returning Shuffle
ユーザー umezoumezo
提出日時 2023-08-23 00:18:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 355 ms / 2,000 ms
コード長 1,658 bytes
コンパイル時間 2,478 ms
コンパイル使用メモリ 219,904 KB
実行使用メモリ 30,456 KB
最終ジャッジ日時 2023-08-23 00:19:04
合計ジャッジ時間 7,653 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
30,456 KB
testcase_01 AC 355 ms
30,436 KB
testcase_02 AC 342 ms
30,260 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 255 ms
30,272 KB
testcase_20 AC 257 ms
30,300 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 325 ms
30,224 KB
testcase_25 AC 315 ms
30,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

class Dis{
  public:
  vector<ll> rank,p,siz;
  
  Dis(int s){
    rank.resize(s,0);
    p.resize(s,0);
    siz.resize(s,1);
    rep(i,s) makeSet(i);
  }
  
  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
  }
  
  bool same(int x,int y){
    return root(x)==root(y);
  }
  
  void unite(int x,int y){
    if(same(x,y)) return;
    link(root(x),root(y));
  }
  
  void link(int x,int y){
    if(rank[x]>rank[y]){
      p[y]=x;
      siz[x]+=siz[y];
    }
    else{
      p[x]=y;
      siz[y]+=siz[x];
      if(rank[x]==rank[y]) rank[y]++;
    }
  }
  
  int root(int x){
    if(x != p[x]) p[x]=root(p[x]);
    return p[x];
  }
  
  int size(int x){
    return siz[root(x)];
  }
};

const int MOD=998244353;
map<ll,ll> prime_factor(ll x){
  map<ll,ll> res;
  for(ll i=2;i*i<=x;i++){
    while(x%i==0){
      res[i]++;
      x/=i;
    }
  }
  if(x!=1) res[x]++;
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n,m;
  cin>>n>>m;
  vector<int> A(n);
  rep(i,n) A[i]=i;
  rep(i,m){
    int t;
    cin>>t;
    vector<int> S(t);
    rep(j,t){
      cin>>S[j];
      S[j]--;
    }
    int k=A[S[t-1]];
    for(int j=t-1;j>0;j--) A[S[j]]=A[S[j-1]];
    A[S[0]]=k;
  }
  Dis ds=Dis(n);
  rep(i,n) ds.unite(i,A[i]);
  set<int> s;
  rep(i,n) s.insert(ds.size(i));
  map<ll,ll> M;
  for(auto x:s){
    map<ll,ll> ma=prime_factor(x);
    for(auto [a,b]:ma) M[a]=max(M[a],b);
  }
  ll ans=1;
  for(auto [a,b]:M){
    rep(i,b) ans=ans*a%MOD;
  }
  cout<<ans<<endl;

  return 0;
}
0