結果

問題 No.1864 Shortest Paths Counting
ユーザー 👑 hitonanodehitonanode
提出日時 2023-05-10 07:05:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 1,356 bytes
コンパイル時間 1,213 ms
コンパイル使用メモリ 117,400 KB
実行使用メモリ 8,160 KB
最終ジャッジ日時 2023-08-17 15:23:15
合計ジャッジ時間 4,200 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 77 ms
6,508 KB
testcase_10 AC 79 ms
6,520 KB
testcase_11 AC 75 ms
6,080 KB
testcase_12 AC 88 ms
7,272 KB
testcase_13 AC 76 ms
6,100 KB
testcase_14 AC 79 ms
6,640 KB
testcase_15 AC 81 ms
6,832 KB
testcase_16 AC 76 ms
6,736 KB
testcase_17 AC 80 ms
6,688 KB
testcase_18 AC 80 ms
6,764 KB
testcase_19 AC 77 ms
6,452 KB
testcase_20 AC 82 ms
6,876 KB
testcase_21 AC 76 ms
6,068 KB
testcase_22 AC 79 ms
6,672 KB
testcase_23 AC 78 ms
6,460 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 89 ms
8,160 KB
testcase_26 AC 54 ms
6,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0