結果

問題 No.1864 Shortest Paths Counting
ユーザー 👑 colognecologne
提出日時 2022-03-04 22:06:45
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 309 ms / 2,000 ms
コード長 1,522 bytes
コンパイル時間 3,261 ms
コンパイル使用メモリ 262,448 KB
実行使用メモリ 10,128 KB
最終ジャッジ日時 2023-09-26 01:09:03
合計ジャッジ時間 10,048 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 303 ms
9,804 KB
testcase_10 AC 301 ms
9,872 KB
testcase_11 AC 285 ms
9,776 KB
testcase_12 AC 302 ms
9,772 KB
testcase_13 AC 301 ms
9,936 KB
testcase_14 AC 299 ms
10,128 KB
testcase_15 AC 288 ms
9,920 KB
testcase_16 AC 287 ms
9,940 KB
testcase_17 AC 286 ms
9,792 KB
testcase_18 AC 299 ms
10,092 KB
testcase_19 AC 294 ms
9,828 KB
testcase_20 AC 309 ms
9,772 KB
testcase_21 AC 305 ms
9,864 KB
testcase_22 AC 299 ms
9,860 KB
testcase_23 AC 299 ms
9,860 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 258 ms
9,940 KB
testcase_26 AC 235 ms
9,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/segtree>
#include <atcoder/modint>
#include <bits/stdc++.h>
using namespace std;

using Mint = atcoder::modint998244353;
Mint add(Mint a, Mint b)
{
    return a + b;
}
Mint e() { return 0; }
using Seg = atcoder::segtree<Mint, add, e>;

int main()
{
    int N;
    cin >> N;
    vector<int> X, Y;
    for (int i = 0; i < N; ++i)
    {
        int a, b;
        cin >> a >> b;
        X.emplace_back(a + b);
        Y.emplace_back(a - b);
    }
    vector<int> xc = X, yc = Y;
    sort(xc.begin(), xc.end());
    xc.erase(unique(xc.begin(), xc.end()), xc.end());
    sort(yc.begin(), yc.end());
    yc.erase(unique(yc.begin(), yc.end()), yc.end());
    for (int &x : X)
        x = lower_bound(xc.begin(), xc.end(), x) - xc.begin();
    for (int &y : Y)
        y = lower_bound(yc.begin(), yc.end(), y) - yc.begin();
    if (X[0] > X[N - 1])
        for (int &x : X)
            x = (int)xc.size() - x - 1;
    if (Y[0] > Y[N - 1])
        for (int &y : Y)
            y = (int)yc.size() - y - 1;

    vector<int> ord(N);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int a, int b)
         { return make_pair(X[a], Y[a]) < make_pair(X[b], Y[b]); });
    Seg seg(Y.size());
    for (int a : ord)
    {
        int x = X[a], y = Y[a];
        if (a == N - 1)
        {
            cout << seg.prod(0, y + 1).val() << endl;
            return 0;
        }
        if (a == 0)
            seg.set(y, 1);
        else
            seg.set(y, seg.prod(0, y + 1) + seg.get(y));
    }
}
0