結果
問題 | No.1864 Shortest Paths Counting |
ユーザー |
![]() |
提出日時 | 2023-05-10 07:05:12 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 77 ms / 2,000 ms |
コード長 | 1,356 bytes |
コンパイル時間 | 1,151 ms |
コンパイル使用メモリ | 119,052 KB |
実行使用メモリ | 8,184 KB |
最終ジャッジ日時 | 2024-11-26 12:28:10 |
合計ジャッジ時間 | 3,754 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
#include <algorithm>#include <iostream>#include <utility>#include <vector>using namespace std;#include <atcoder/modint>using mint = atcoder::modint998244353;#include <atcoder/fenwicktree>int main() {cin.tie(nullptr), ios::sync_with_stdio(false);int N;cin >> N;vector<pair<long long, long long>> A(N);for (auto &[x, y] : A) {long long u, v;cin >> u >> v;x = u + v, y = u - v;}while (true) {if (A.back().second - A.front().second >= 0 and A.back().first - A.front().first >= 0) break;for (auto &[x, y] : A) {swap(x, y);y = -y;}}const auto [xlo, ylo] = A.front();const auto [xhi, yhi] = A.back();vector<long long> ys{ylo, yhi}, yq;sort(A.begin() + 1, A.end() - 1);for (int i = 1; i < N - 1; ++i) {auto [x, y] = A.at(i);if (xlo <= x and x <= xhi and ylo <= y and y <= yhi) {ys.push_back(y);yq.push_back(y);}}sort(ys.begin(), ys.end());atcoder::fenwick_tree<mint> bit(ys.size());bit.add(0, 1);mint ret = 1;for (auto y : yq) {int idx = lower_bound(ys.begin(), ys.end(), y) - ys.begin();auto s = bit.sum(0, idx + 1);ret += s;bit.add(idx, s);}cout << ret.val() << endl;}