結果

問題 No.1864 Shortest Paths Counting
ユーザー ChipppppChippppp
提出日時 2022-03-02 20:58:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 392 ms / 2,000 ms
コード長 1,293 bytes
コンパイル時間 4,676 ms
コンパイル使用メモリ 273,116 KB
実行使用メモリ 20,984 KB
最終ジャッジ日時 2023-09-23 13:33:35
合計ジャッジ時間 12,781 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 374 ms
19,696 KB
testcase_10 AC 363 ms
19,864 KB
testcase_11 AC 386 ms
19,684 KB
testcase_12 AC 380 ms
20,260 KB
testcase_13 AC 372 ms
19,372 KB
testcase_14 AC 392 ms
19,788 KB
testcase_15 AC 383 ms
19,916 KB
testcase_16 AC 369 ms
19,636 KB
testcase_17 AC 359 ms
19,912 KB
testcase_18 AC 370 ms
19,824 KB
testcase_19 AC 377 ms
19,632 KB
testcase_20 AC 384 ms
19,952 KB
testcase_21 AC 363 ms
19,584 KB
testcase_22 AC 364 ms
19,820 KB
testcase_23 AC 375 ms
19,788 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 389 ms
20,984 KB
testcase_26 AC 296 ms
19,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

// 座標圧縮
map<ll, int> compress(const 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<ll> X(N), Y(N);
  for (int i = 0; i < N; ++i) {
    ll a, b;
    cin >> a >> b;
    X[i] = a + b;
    Y[i] = a - b;
  }

  // 座標を反転しておく
  if (X.front() > X.back()) {
    for (auto& i: X) i = -i;
  }
  if (Y.front() > Y.back()) {
    for (auto& i: Y) i = -i;
  }

  // y座標を圧縮
  auto mem = compress(Y);
  for (auto& i: Y) i = mem[i];

  // x, y座標が範囲内の点のみソート
  vector<pair<ll, ll>> points;
  for (int i = 0; i < N; ++i) {
    if (X.front() <= X[i] && X[i] <= X.back() && Y.front() <= Y[i] && Y[i] <= Y.back()) points.push_back({X[i], Y[i]});
  }
  sort(points.begin(), points.end());

  // DP
  atcoder::fenwick_tree<atcoder::modint998244353> ft(mem.size());
  ft.add(points.front().second, 1);
  for (int i = 1; i < points.size() - 1; ++i) {
    ft.add(points[i].second, ft.sum(0, points[i].second + 1));
  }

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