結果

問題 No.1864 Shortest Paths Counting
ユーザー 👑 colognecologne
提出日時 2022-03-04 22:05:25
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,472 bytes
コンパイル時間 3,923 ms
コンパイル使用メモリ 262,588 KB
実行使用メモリ 10,204 KB
最終ジャッジ日時 2023-09-26 01:05:58
合計ジャッジ時間 10,828 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 319 ms
10,204 KB
testcase_10 AC 315 ms
10,004 KB
testcase_11 AC 312 ms
9,808 KB
testcase_12 AC 314 ms
10,028 KB
testcase_13 AC 314 ms
10,004 KB
testcase_14 AC 320 ms
9,860 KB
testcase_15 AC 314 ms
9,864 KB
testcase_16 AC 317 ms
10,012 KB
testcase_17 AC 318 ms
10,016 KB
testcase_18 AC 317 ms
9,940 KB
testcase_19 AC 317 ms
9,824 KB
testcase_20 AC 314 ms
9,868 KB
testcase_21 AC 319 ms
9,948 KB
testcase_22 AC 312 ms
9,860 KB
testcase_23 AC 318 ms
9,860 KB
testcase_24 WA -
testcase_25 AC 276 ms
10,004 KB
testcase_26 AC 238 ms
9,948 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 == 0)
            seg.set(y, 1);
        else
            seg.set(y, seg.prod(0, y + 1) + seg.get(y));
        if (a == N - 1)
            cout << seg.get(y).val() << endl;
    }
}
0