結果

問題 No.1864 Shortest Paths Counting
ユーザー Chippppp
提出日時 2021-12-26 02:38:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 507 ms / 2,000 ms
コード長 1,327 bytes
コンパイル時間 4,792 ms
コンパイル使用メモリ 265,020 KB
最終ジャッジ日時 2025-01-27 06:54:22
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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;
}
// pointsy
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);
// DP
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';
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0