結果

問題 No.2588 Increasing Record
ユーザー noshi91noshi91
提出日時 2023-12-16 01:21:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 379 ms / 3,000 ms
コード長 1,030 bytes
コンパイル時間 2,317 ms
コンパイル使用メモリ 220,788 KB
実行使用メモリ 43,196 KB
最終ジャッジ日時 2023-12-16 01:21:32
合計ジャッジ時間 14,765 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 297 ms
22,400 KB
testcase_13 AC 312 ms
22,400 KB
testcase_14 AC 291 ms
22,400 KB
testcase_15 AC 287 ms
22,656 KB
testcase_16 AC 304 ms
27,392 KB
testcase_17 AC 350 ms
32,588 KB
testcase_18 AC 318 ms
37,956 KB
testcase_19 AC 307 ms
42,176 KB
testcase_20 AC 290 ms
43,064 KB
testcase_21 AC 324 ms
43,184 KB
testcase_22 AC 289 ms
43,196 KB
testcase_23 AC 285 ms
43,196 KB
testcase_24 AC 288 ms
43,196 KB
testcase_25 AC 307 ms
32,588 KB
testcase_26 AC 288 ms
37,956 KB
testcase_27 AC 273 ms
43,124 KB
testcase_28 AC 271 ms
42,976 KB
testcase_29 AC 298 ms
43,196 KB
testcase_30 AC 309 ms
32,588 KB
testcase_31 AC 337 ms
37,956 KB
testcase_32 AC 379 ms
42,176 KB
testcase_33 AC 345 ms
43,064 KB
testcase_34 AC 346 ms
43,184 KB
testcase_35 AC 351 ms
43,196 KB
testcase_36 AC 378 ms
43,196 KB
testcase_37 AC 278 ms
43,196 KB
testcase_38 AC 305 ms
32,588 KB
testcase_39 AC 313 ms
43,196 KB
testcase_40 AC 291 ms
43,196 KB
testcase_41 AC 277 ms
43,196 KB
testcase_42 AC 277 ms
43,196 KB
testcase_43 AC 286 ms
43,196 KB
testcase_44 AC 272 ms
33,216 KB
testcase_45 AC 266 ms
37,180 KB
testcase_46 AC 254 ms
42,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#include <atcoder/modint>
using mint = atcoder::modint998244353;

#include <atcoder/dsu>

int main() {
  int N, M;
  cin >> N >> M;

  vector<set<int>> l(N), r(N);
  vector<mint> a(N);
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    l[v].insert(u);
    r[u].insert(v);
  }

  vector<mint> dp(N, 1);
  atcoder::dsu dsu(N);
  // invariant: true dp[v] = dp[v] + sum_{v in r[u]} a[u]
  for (int i = 0; i < N; i++) {
    int x = i;
    for (int j : l[i]) {
      int y = dsu.leader(j);
      if (x == y)
        continue;
      if (r[y].erase(i))
        dp[i] += a[y];
      dsu.merge(x, y);
      if (dsu.leader(i) == y)
        swap(x, y);
      if (r[x].size() < r[y].size())
        swap(r[x], r[y]), swap(a[x], a[y]);
      for (int k : r[y]) {
        dp[k] += a[y];
        if (r[x].insert(k).second)
          dp[k] -= a[x];
      }
      r[y].clear();
    }
    a[x] += dp[i];
  }

  cout << accumulate(dp.begin(), dp.end(), mint(0)).val();
}
0