結果

問題 No.1864 Shortest Paths Counting
ユーザー 沙耶花沙耶花
提出日時 2022-03-04 22:37:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 359 ms / 2,000 ms
コード長 1,334 bytes
コンパイル時間 4,523 ms
コンパイル使用メモリ 270,668 KB
実行使用メモリ 16,664 KB
最終ジャッジ日時 2023-09-26 01:46:02
合計ジャッジ時間 11,990 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 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,380 KB
testcase_05 AC 2 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 346 ms
16,664 KB
testcase_10 AC 354 ms
15,896 KB
testcase_11 AC 344 ms
15,768 KB
testcase_12 AC 349 ms
15,708 KB
testcase_13 AC 359 ms
16,212 KB
testcase_14 AC 354 ms
16,016 KB
testcase_15 AC 351 ms
15,624 KB
testcase_16 AC 347 ms
15,972 KB
testcase_17 AC 350 ms
15,752 KB
testcase_18 AC 349 ms
15,956 KB
testcase_19 AC 347 ms
15,888 KB
testcase_20 AC 347 ms
15,900 KB
testcase_21 AC 349 ms
16,200 KB
testcase_22 AC 349 ms
15,704 KB
testcase_23 AC 350 ms
15,748 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 283 ms
12,960 KB
testcase_26 AC 234 ms
13,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000000
int n;
vector<long long> x,y;

mint op(mint a,mint b){
	return a+b;
}

mint e(){
	return 0;
}

int main(){
	
	
	cin>>n;
	x.resize(n),y.resize(n);
	rep(i,n){
		cin>>x[i]>>y[i];
		long long t = x[i]+y[i];
		y[i] = x[i]-y[i];
		x[i] = t;
	}
	
	
	
	for(int i=n-1;i>=0;i--){
		y[i] -= y[0];
		x[i] -= x[0];
	}
	rep(i,n){
		if(y.back()<0)y[i] *= -1;
		if(x.back()<0)x[i] *= -1;
	}
	vector<long long> t;
	rep(i,n){
		t.push_back(x[i]);
		t.push_back(y[i]);
	}
	sort(t.begin(),t.end());
	t.erase(unique(t.begin(),t.end()),t.end());
	rep(i,n){
		x[i] = distance(t.begin(),lower_bound(t.begin(),t.end(),x[i]));
		y[i] = distance(t.begin(),lower_bound(t.begin(),t.end(),y[i]));
	}
	
	vector<int> ind(n);
	rep(i,n)ind[i] = i;
	
	sort(ind.begin(),ind.end(),[&](int a,int b){
		return make_pair(x[a],y[a])<make_pair(x[b],y[b]);
	});
	
	
	segtree<mint,op,e> seg(t.size()+7);
	mint ans;
	rep(i,n){
		if(ind[i]==0){
			seg.set(y[ind[i]],1);
		}
		else if(ind[i]==n-1){
			ans = seg.prod(0,y[ind[i]]+1);
		}
		else{
			mint tt = seg.prod(0,y[ind[i]]+1);
			seg.set(y[ind[i]],seg.get(y[ind[i]])+tt);
		}
	}
	cout<<ans.val()<<endl;
	
	
	return 0;
}
0