結果

問題 No.2428 Returning Shuffle
ユーザー Nzt3Nzt3
提出日時 2023-08-19 00:33:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 1,174 bytes
コンパイル時間 2,050 ms
コンパイル使用メモリ 212,356 KB
実行使用メモリ 11,172 KB
最終ジャッジ日時 2024-05-06 07:29:54
合計ジャッジ時間 4,527 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
11,136 KB
testcase_01 AC 184 ms
11,136 KB
testcase_02 AC 181 ms
11,136 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 128 ms
11,136 KB
testcase_20 AC 129 ms
11,160 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 132 ms
11,172 KB
testcase_25 AC 131 ms
11,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int mod=998244353;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  cin>>N>>M;
  vector<int>P(N);
  iota(P.begin(),P.end(),0);
  for(int i=0;i<M;i++){
    int T;
    cin>>T;
    vector<int>A(T);
    for(int &j:A)cin>>j,--j;
    int p=P[A[T-1]];
    for(int j=T-2;j>=0;j--){
      P[A[j+1]]=P[A[j]];
    }
    P[A[0]]=p;
  }
  vector<int>prime(N+1,-1);
  for(int i=2;i<=N;i++){
    if(prime[i]!=-1)continue;
    for(int j=i*2;j<=N;j+=i){
      prime[j]=i;
    }
  }
  vector<bool>vst(N);
  map<int,int>lcm_cnt;
  for(int i=0;i<N;i++){
    if(vst[i])continue;
    int cnt=1,t=P[i];
    vst[i]=1;
    while(t!=i){
      vst[t]=1;
      cnt+=1;
      t=P[t];
    }
    map<int,int>n_prime;
    while(cnt>1){
      if(prime[cnt]!=-1){
        n_prime[prime[cnt]]+=1;
        cnt/=prime[cnt];
      }else{
        n_prime[cnt]+=1;
        cnt/=cnt;
      }
    }
    for(auto j:n_prime){
      lcm_cnt[j.first]=max(lcm_cnt[j.first],j.second);
    }
  }
  ll ans=1;
  for(auto i:lcm_cnt){
    for(int j=0;j<i.second;j++){
      ans=ans*i.first%mod;
    }
  }
  cout<<ans<<'\n';
}
0