結果
問題 | No.2428 Returning Shuffle |
ユーザー |
|
提出日時 | 2023-09-28 15:59:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 261 ms / 2,000 ms |
コード長 | 1,960 bytes |
コンパイル時間 | 2,158 ms |
コンパイル使用メモリ | 202,324 KB |
最終ジャッジ日時 | 2025-02-17 02:47:48 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:93:16: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘i64’ {aka ‘long int’} [-Wformat=] 93 | printf("%lld\n", ans); | ~~~^ ~~~ | | | | | i64 {aka long int} | long long int | %ld main.cpp:26:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 26 | scanf("%d%d", &n, &m); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:33:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 33 | scanf("%d", &t); | ~~~~~^~~~~~~~~~ main.cpp:36:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 36 | for (auto& v : s) scanf("%d", &v), --v; | ~~~~~^~~~~~~~~~
ソースコード
#include <bits/stdc++.h>using namespace std::literals::string_literals;using i64 = std::int_fast64_t;using std::cerr;using std::cin;using std::cout;using std::endl;#if defined(DONLINE_JUDGE)#define NDEBUG#elif defined(ONLINE_JUDGE)#define NDEBUG#endiftemplate <typename T>std::vector<T> make_v(size_t a) {return std::vector<T>(a);}template <typename T, typename... Ts>auto make_v(size_t a, Ts... ts) {return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));}int main() {int n, m;scanf("%d%d", &n, &m);std::vector<int> p(n);std::iota(p.begin(), p.end(), 0);for (int i = 0; i < m; ++i) {int t;scanf("%d", &t);std::vector<int> s(t);for (auto& v : s) scanf("%d", &v), --v;const int o = p[s.back()];for (int j = t - 1; j > 0; --j) {p[s[j]] = p[s[j - 1]];}p[s.front()] = o;}std::vector<int> minp(n + 1, -1);for (int p = 2; p <= n; ++p) {if (minp[p] != -1) continue;for (int i = p; i <= n; i += p) {if (minp[i] != -1) continue;minp[i] = p;}}std::map<int, int> lcm;std::vector<int> used(n);for (int i = 0; i < n; ++i) {if (used[i]) continue;used[i] = 1;int size = 1;{int now = p[i];while (now != i) {++size;used[now] = 1;now = p[now];}}while (size != 1) {const int p = minp[size];int cnt = 0;while (size % p == 0) {++cnt;size /= p;}lcm[p] = std::max(lcm[p], cnt);}}const int MOD = 998244353;i64 ans = 1;for (auto [p, cnt] : lcm) {for (int i = 0; i < cnt; ++i) ans = ans * p % MOD;}printf("%lld\n", ans);return 0;}