結果

問題 No.2428 Returning Shuffle
ユーザー kt_soupkt_soup
提出日時 2023-08-18 21:57:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 799 bytes
コンパイル時間 663 ms
コンパイル使用メモリ 72,932 KB
実行使用メモリ 15,108 KB
最終ジャッジ日時 2024-05-06 03:58:17
合計ジャッジ時間 4,926 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 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 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
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 2 ms
5,376 KB
testcase_24 AC 339 ms
14,992 KB
testcase_25 AC 339 ms
15,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
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;
}

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)]++;
  long long ans = 1;
  for(int i=0;i<N;i++)if(c[i])ans = ans/gcd(ans,c[i])*c[i]%998244353;
  cout << ans << endl;
}
0