結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,480 KB
testcase_01 AC 2 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 1 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 302 ms
22,400 KB
testcase_13 AC 271 ms
22,400 KB
testcase_14 AC 335 ms
22,400 KB
testcase_15 AC 2,558 ms
22,656 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

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