結果

問題 No.1864 Shortest Paths Counting
ユーザー ChipppppChippppp
提出日時 2021-12-26 02:26:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 431 ms / 2,000 ms
コード長 1,383 bytes
コンパイル時間 5,539 ms
コンパイル使用メモリ 275,008 KB
実行使用メモリ 21,896 KB
最終ジャッジ日時 2023-09-23 13:33:51
合計ジャッジ時間 13,640 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 399 ms
21,896 KB
testcase_10 AC 394 ms
21,708 KB
testcase_11 AC 406 ms
21,880 KB
testcase_12 AC 405 ms
21,772 KB
testcase_13 AC 395 ms
21,884 KB
testcase_14 AC 405 ms
21,720 KB
testcase_15 AC 392 ms
21,760 KB
testcase_16 AC 381 ms
21,848 KB
testcase_17 AC 387 ms
21,884 KB
testcase_18 AC 403 ms
21,876 KB
testcase_19 AC 422 ms
21,840 KB
testcase_20 AC 423 ms
21,888 KB
testcase_21 AC 431 ms
21,712 KB
testcase_22 AC 406 ms
21,780 KB
testcase_23 AC 420 ms
21,780 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 429 ms
21,724 KB
testcase_26 AC 357 ms
21,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using ll = long long;
constexpr ll mod = 998244353;

// 座標圧縮
map<ll, int> compress(vector<ll> a) {
  map<ll, int> mem;
  for (auto i: a) mem[i] = 0;
  int cnt = 0;
  for (auto& [i, j]: mem) j = cnt++;
  return mem;
}

int main() {
  // 入力
  int n;
  cin >> n;
  vector<pair<ll, ll>> points(n);
  for (auto& [i, j]: points) {
    ll x, y;
    cin >> x >> y;
    i = x + y;
    j = y - x;
  }

  // 座標を反転しておく
  if (points.front().first > points.back().first) {
    for (auto& [i, j]: points) i = -i;
  }
  if (points.front().second > points.back().second) {
    for (auto& [i, j]: points) j = -j;
  }

  // pointsのy座標を座標圧縮
  vector<ll> y(n);
  for (int i = 0; i < n; ++i) y[i] = points[i].second;
  auto mem = compress(y);
  for (auto& [i, j]: points) j = mem[j];

  // ソート
  sort(points.begin() + 1, points.end() - 1);

  // y座標がより小さい頂点の個数を順に調べる
  atcoder::fenwick_tree<atcoder::modint998244353> ft(mem.size());
  ft.add(points.front().second, 1);
  for (int i = 1; i < n - 1; ++i) {
    if (points[i].first < points.front().first || points.back().first < points[i].first) continue;
    ft.add(points[i].second, ft.sum(0, points[i].second + 1));
  }

  // 出力
  cout << ft.sum(0, points.back().second + 1).val() << '\n';
}
0