結果

問題 No.2428 Returning Shuffle
ユーザー kt_soupkt_soup
提出日時 2023-08-18 22:09:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 435 ms / 2,000 ms
コード長 1,265 bytes
コンパイル時間 1,108 ms
コンパイル使用メモリ 84,300 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2024-05-06 04:14:34
合計ジャッジ時間 5,419 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 304 ms
18,944 KB
testcase_01 AC 426 ms
18,816 KB
testcase_02 AC 435 ms
18,944 KB
testcase_03 AC 10 ms
7,168 KB
testcase_04 AC 9 ms
7,296 KB
testcase_05 AC 10 ms
7,296 KB
testcase_06 AC 10 ms
7,168 KB
testcase_07 AC 9 ms
7,168 KB
testcase_08 AC 9 ms
7,296 KB
testcase_09 AC 9 ms
7,168 KB
testcase_10 AC 10 ms
7,168 KB
testcase_11 AC 10 ms
7,168 KB
testcase_12 AC 9 ms
7,168 KB
testcase_13 AC 9 ms
7,168 KB
testcase_14 AC 9 ms
7,168 KB
testcase_15 AC 9 ms
7,168 KB
testcase_16 AC 10 ms
7,168 KB
testcase_17 AC 10 ms
7,168 KB
testcase_18 AC 9 ms
7,168 KB
testcase_19 AC 325 ms
18,944 KB
testcase_20 AC 325 ms
18,944 KB
testcase_21 AC 10 ms
7,168 KB
testcase_22 AC 9 ms
7,168 KB
testcase_23 AC 10 ms
7,168 KB
testcase_24 AC 324 ms
18,828 KB
testcase_25 AC 323 ms
18,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<map>
using namespace std;
int par(int x,vector<int>& p) {
  if(x == p[x])return x;
  else return p[x] = par(p[x],p);
}

long long gcd(long long a,long long b) {
  if(b)return gcd(b,a%b);
  else return a;
}

long long pow(long long a,long long b) {
  if(b)return pow(a*a%998244353,b/2)*(b&1?a:1)%998244353;
  else return 1;
}

int main() {
  int N,M,t;
  cin >> N >> M;
  vector<int> p(N);
  for(int i=0;i<N;i++)p[i] = i;
  for(int i=0;i<M;i++) {
    cin >> t;
    vector<int> s(t);
    for(int j=0;j<t;j++)cin >> s[j];
    int tt = p[s[t-1]-1];
    for(int j=t-1;j>0;j--)p[s[j]-1] = p[s[j-1]-1];
    p[s[0]-1] = tt;
  }
  vector<int> pa(N),c(N,0);
  for(int i=0;i<N;i++)pa[i] = i;
  for(int i=0;i<N;i++)pa[par(i,pa)] = par(p[i],pa);
  for(int i=0;i<N;i++)c[par(i,pa)]++;
  vector<int> f(1000010,0);
  for(int i=2;i<1000010;i++)if(!f[i]) {
    f[i] = i;
    for(long long j=i;i*j<1000010;j++)f[i*j] = i;
  }
  long long ans = 1;
  map<int,int> m;
  for(int i=0;i<N;i++)if(c[i]) {
    map<int,int> mm;
    while(c[i] > 1) {
      mm[f[c[i]]]++;
      c[i] /= f[c[i]];
    }
    for(auto j : mm)m[j.first] = max(m[j.first],j.second);
  }
  for(auto j : m)ans = ans*pow(j.first,j.second)%998244353;
  cout << ans << endl;
}
0