結果
| 問題 |
No.1864 Shortest Paths Counting
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2022-03-07 13:12:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 68 ms / 2,000 ms |
| コード長 | 1,852 bytes |
| コンパイル時間 | 694 ms |
| コンパイル使用メモリ | 60,728 KB |
| 実行使用メモリ | 11,004 KB |
| 最終ジャッジ日時 | 2024-07-22 07:39:49 |
| 合計ジャッジ時間 | 3,224 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 1864.cc: No.1864 Shortest Paths Counting - yukicoder
*/
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 200000;
const int MOD = 998244353;
/* typedef */
typedef long long ll;
typedef pair<ll,ll> pll;
template <typename T>
struct BIT {
int n;
vector<T> bits;
BIT() {}
BIT(int _n) { init(_n); }
void init(int _n) {
n = _n;
bits.resize(n + 1, 0);
}
T sum(int x) {
x = min(x, n);
T s = 0;
while (x > 0) {
s = (s + bits[x]) % MOD;
x -= (x & -x);
}
return s;
}
void add(int x, T v) {
if (x <= 0) return;
while (x <= n) {
bits[x] = (bits[x] + v) % MOD;
x += (x & -x);
}
}
};
/* global variables */
ll xs[MAX_N], ys[MAX_N], uys[MAX_N];
pll ps[MAX_N];
BIT<int> bit;
/* subroutines */
/* main */
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int xi, yi;
scanf("%d%d", &xi, &yi);
xs[i] = xi + yi, ys[i] = xi - yi;
}
bool xrv = (xs[0] > xs[n - 1]);
bool yrv = (ys[0] > ys[n - 1]);
for (int i = 0; i < n; i++) {
if (xrv) xs[i] = -xs[i];
if (yrv) ys[i] = -ys[i];
}
ll x0 = xs[0], y0 = ys[0];
ll gx = xs[n - 1] - x0, gy = ys[n - 1] - y0;
int m = 0;
for (int i = 0; i < n; i++) {
ll xi = xs[i] - x0, yi = ys[i] - y0;
if (0 <= xi && xi <= gx && 0 <= yi && yi <= gy) ps[m++] = pll(xi, yi);
}
if (m > 2) sort(ps + 1, ps + m - 1);
for (int i = 0; i < m; i++) uys[i] = ps[i].second;
sort(uys, uys + m);
int k = unique(uys, uys + m) - uys;
bit.init(k);
bit.add(1, 1);
for (int i = 1; i < m - 1; i++) {
int yi = lower_bound(uys, uys + k, ps[i].second) - uys;
int di = bit.sum(yi + 1);
bit.add(yi + 1, di);
}
int sum = bit.sum(k);
printf("%d\n", sum);
return 0;
}
tnakao0123