結果
問題 | No.2588 Increasing Record |
ユーザー | Kude |
提出日時 | 2023-12-16 01:01:03 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 559 ms / 3,000 ms |
コード長 | 2,122 bytes |
コンパイル時間 | 3,171 ms |
コンパイル使用メモリ | 287,104 KB |
実行使用メモリ | 45,624 KB |
最終ジャッジ日時 | 2023-12-16 01:01:26 |
合計ジャッジ時間 | 16,011 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,676 KB |
testcase_01 | AC | 4 ms
6,676 KB |
testcase_02 | AC | 2 ms
6,676 KB |
testcase_03 | AC | 2 ms
6,676 KB |
testcase_04 | AC | 1 ms
6,676 KB |
testcase_05 | AC | 2 ms
6,676 KB |
testcase_06 | AC | 2 ms
6,676 KB |
testcase_07 | AC | 2 ms
6,676 KB |
testcase_08 | AC | 2 ms
6,676 KB |
testcase_09 | AC | 2 ms
6,676 KB |
testcase_10 | AC | 2 ms
6,676 KB |
testcase_11 | AC | 2 ms
6,676 KB |
testcase_12 | AC | 47 ms
6,676 KB |
testcase_13 | AC | 52 ms
6,676 KB |
testcase_14 | AC | 53 ms
6,676 KB |
testcase_15 | AC | 70 ms
6,676 KB |
testcase_16 | AC | 139 ms
13,460 KB |
testcase_17 | AC | 208 ms
21,248 KB |
testcase_18 | AC | 262 ms
28,752 KB |
testcase_19 | AC | 371 ms
35,456 KB |
testcase_20 | AC | 380 ms
36,508 KB |
testcase_21 | AC | 399 ms
36,624 KB |
testcase_22 | AC | 467 ms
38,424 KB |
testcase_23 | AC | 462 ms
38,300 KB |
testcase_24 | AC | 421 ms
37,144 KB |
testcase_25 | AC | 286 ms
24,112 KB |
testcase_26 | AC | 351 ms
31,088 KB |
testcase_27 | AC | 481 ms
37,884 KB |
testcase_28 | AC | 484 ms
37,640 KB |
testcase_29 | AC | 481 ms
37,952 KB |
testcase_30 | AC | 175 ms
20,352 KB |
testcase_31 | AC | 216 ms
27,628 KB |
testcase_32 | AC | 309 ms
34,032 KB |
testcase_33 | AC | 273 ms
35,480 KB |
testcase_34 | AC | 266 ms
35,600 KB |
testcase_35 | AC | 269 ms
35,608 KB |
testcase_36 | AC | 264 ms
35,608 KB |
testcase_37 | AC | 559 ms
38,844 KB |
testcase_38 | AC | 204 ms
22,312 KB |
testcase_39 | AC | 399 ms
45,608 KB |
testcase_40 | AC | 413 ms
45,624 KB |
testcase_41 | AC | 305 ms
45,548 KB |
testcase_42 | AC | 305 ms
45,540 KB |
testcase_43 | AC | 310 ms
45,532 KB |
testcase_44 | AC | 254 ms
24,568 KB |
testcase_45 | AC | 309 ms
29,864 KB |
testcase_46 | AC | 370 ms
36,872 KB |
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; using mint = modint998244353; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; VVI to(n); rep(_, m) { int u, v; cin >> u >> v; u--, v--; to[u].emplace_back(v); to[v].emplace_back(u); } vector<pair<map<int, mint>, mint>> dp(n); mint ans; dsu uf(n); rep(v, n) { dp[v].first[v] = 1; int vl = v; for (int u : to[v]) if (u < v) { int ul = uf.leader(u); if (ul == vl) continue; if (dp[ul].first.size() > dp[vl].first.size()) { swap(dp[ul], dp[vl]); } for (auto [i, c] : dp[ul].first) { auto it = dp[vl].first.find(i); if (it == dp[vl].first.end()) dp[vl].first[i] = c + dp[ul].second - dp[vl].second; else { it->second += c + dp[ul].second; } } // if (v == 2) exit(0); dp[ul].first.clear(); int l = uf.merge(ul, vl); if (vl != l) { dp[l] = move(dp[vl]); vl = l; } } mint val = dp[vl].first[v] + dp[vl].second; ans += val; // cout << v << ' ' << val.val() << endl; for (int u : to[v]) if (u > v) { auto it = dp[vl].first.find(u); if (it == dp[vl].first.end()) dp[vl].first[u] = -dp[vl].second; } dp[vl].second += val; // if (v == 1) cout << (dp[vl].first[2] + dp[vl].second).val() << endl, exit(0); } cout << ans.val() << '\n'; }