結果

問題 No.2230 Good Omen of White Lotus
ユーザー publfl2publfl2
提出日時 2023-02-24 22:37:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 1,471 bytes
コンパイル時間 588 ms
コンパイル使用メモリ 56,184 KB
実行使用メモリ 7,008 KB
最終ジャッジ日時 2023-10-11 06:34:48
合計ジャッジ時間 5,808 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
5,088 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 43 ms
4,348 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 64 ms
4,568 KB
testcase_17 AC 64 ms
4,564 KB
testcase_18 AC 64 ms
4,612 KB
testcase_19 AC 65 ms
4,612 KB
testcase_20 AC 5 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 7 ms
4,352 KB
testcase_23 AC 8 ms
4,348 KB
testcase_24 AC 64 ms
4,352 KB
testcase_25 AC 65 ms
4,348 KB
testcase_26 AC 66 ms
4,984 KB
testcase_27 AC 125 ms
4,572 KB
testcase_28 AC 116 ms
6,592 KB
testcase_29 AC 133 ms
6,572 KB
testcase_30 AC 141 ms
6,636 KB
testcase_31 AC 139 ms
6,568 KB
testcase_32 AC 136 ms
6,580 KB
testcase_33 AC 180 ms
7,008 KB
testcase_34 AC 182 ms
6,584 KB
testcase_35 AC 180 ms
6,984 KB
testcase_36 AC 183 ms
6,632 KB
testcase_37 AC 184 ms
6,624 KB
testcase_38 AC 184 ms
6,632 KB
testcase_39 AC 188 ms
6,980 KB
testcase_40 AC 92 ms
5,996 KB
testcase_41 AC 51 ms
4,352 KB
testcase_42 AC 107 ms
4,480 KB
testcase_43 AC 43 ms
5,056 KB
testcase_44 AC 142 ms
6,720 KB
testcase_45 AC 59 ms
5,844 KB
testcase_46 AC 106 ms
5,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <algorithm>
#define MOD 998244353

struct segTree{
	int value[800010];
	void setValue(int ind, int val, int l=1, int r=200000, int v=1)
	{
		if(l==r) value[v] = val;
		else
		{
			int h = (l+r)/2;
			if(ind<=h) setValue(ind,val,l,h,2*v);
			else setValue(ind,val,h+1,r,2*v+1);
			value[v] = value[2*v]>value[2*v+1]?value[2*v]:value[2*v+1];
		}
	}
	int getMax(int L, int R,int l=1, int r=200000, int v=1)
	{
		if(L<=l&&r<=R) return value[v];
		else if(r<L) return 0;
		else if(R<l) return 0;
		else
		{
			int h = (l+r)/2;
			int s1 = getMax(L,R,l,h,2*v);
			int s2 = getMax(L,R,h+1,r,2*v+1);
			return s1>s2?s1:s2;
		}
	}
}T;

long long int power(long long int a, long long int b)
{
	long long int ans = 1;
	long long int k = a;
	while(b)
	{
		if(b%2==1) ans*=k, ans%=MOD;
		b/=2;
		k*=k, k%=MOD;
	}
	return ans;
}

long long int inv(long long int k)
{
	return power(k,MOD-2);
}

std::pair<int,int> x[200010];
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	for(int i=1;i<=c;i++)
	{
		int e,f;
		scanf("%d%d",&e,&f);
		x[i] = std::make_pair(e,f);
	}
	std::sort(x+1,x+c+1);
	
	int ans = 0;
	for(int i=1;i<=c;i++)
	{
		int t = T.getMax(1,x[i].second) + 1;
		ans = ans>t?ans:t;
		T.setValue(x[i].second,t);
	}
	
	long long int P = 1;
	for(int i=1;i<=a+b-3;i++) P *= inv(d), P %= MOD;
	for(int i=1;i<=ans;i++) P *= (d-2), P %= MOD;
	for(int i=1;i<=a+b-3-ans;i++) P *= (d-1), P %= MOD;
	printf("%lld",(MOD-P+1)%MOD);
}
0