結果

問題 No.1354 Sambo's Treasure
ユーザー 👑 kmjpkmjp
提出日時 2021-01-17 14:52:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,779 bytes
コンパイル時間 2,649 ms
コンパイル使用メモリ 215,516 KB
実行使用メモリ 105,672 KB
最終ジャッジ日時 2024-05-07 03:55:19
合計ジャッジ時間 20,806 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
21,468 KB
testcase_01 AC 20 ms
21,100 KB
testcase_02 AC 20 ms
22,672 KB
testcase_03 AC 20 ms
22,288 KB
testcase_04 AC 20 ms
21,452 KB
testcase_05 AC 20 ms
22,876 KB
testcase_06 AC 20 ms
21,624 KB
testcase_07 AC 20 ms
22,336 KB
testcase_08 AC 4 ms
11,740 KB
testcase_09 WA -
testcase_10 AC 20 ms
21,928 KB
testcase_11 AC 21 ms
21,452 KB
testcase_12 AC 20 ms
21,340 KB
testcase_13 AC 20 ms
22,488 KB
testcase_14 AC 21 ms
21,432 KB
testcase_15 AC 21 ms
21,304 KB
testcase_16 AC 21 ms
24,144 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 20 ms
22,460 KB
testcase_21 WA -
testcase_22 AC 21 ms
21,216 KB
testcase_23 AC 32 ms
14,812 KB
testcase_24 AC 32 ms
14,788 KB
testcase_25 AC 1,007 ms
105,044 KB
testcase_26 AC 1,006 ms
104,472 KB
testcase_27 AC 1,006 ms
104,616 KB
testcase_28 AC 33 ms
14,684 KB
testcase_29 AC 1,013 ms
104,188 KB
testcase_30 AC 1,007 ms
104,688 KB
testcase_31 AC 1,005 ms
104,192 KB
testcase_32 AC 1,009 ms
104,436 KB
testcase_33 AC 32 ms
14,812 KB
testcase_34 AC 1,008 ms
104,812 KB
testcase_35 AC 32 ms
14,788 KB
testcase_36 AC 1,006 ms
105,416 KB
testcase_37 AC 32 ms
14,820 KB
testcase_38 AC 1,009 ms
104,400 KB
testcase_39 AC 1,005 ms
104,888 KB
testcase_40 AC 1,005 ms
103,800 KB
testcase_41 AC 32 ms
14,816 KB
testcase_42 AC 1,004 ms
104,352 KB
testcase_43 AC 51 ms
28,420 KB
testcase_44 AC 49 ms
28,400 KB
testcase_45 AC 54 ms
30,376 KB
testcase_46 AC 58 ms
28,376 KB
testcase_47 AC 56 ms
28,404 KB
testcase_48 AC 65 ms
30,404 KB
testcase_49 AC 52 ms
28,480 KB
testcase_50 AC 53 ms
30,380 KB
testcase_51 AC 63 ms
30,368 KB
testcase_52 AC 61 ms
30,432 KB
testcase_53 AC 62 ms
30,600 KB
testcase_54 AC 55 ms
30,460 KB
testcase_55 AC 50 ms
28,400 KB
testcase_56 AC 63 ms
30,440 KB
testcase_57 AC 59 ms
28,340 KB
testcase_58 AC 60 ms
30,492 KB
testcase_59 AC 57 ms
30,336 KB
testcase_60 AC 60 ms
28,368 KB
testcase_61 AC 53 ms
30,408 KB
testcase_62 AC 65 ms
28,356 KB
testcase_63 AC 1,006 ms
105,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M,L,K;
int X[202020],Y[202020];
vector<int> S[202020];
ll dp[202020][103];
ll pat[103][103][103];
const ll mo=998244353;
ll comb(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>L>>K;
	FOR(i,M) {
		cin>>X[i+1]>>Y[i+1];
		S[i].push_back(i);
		S[i].push_back(i+1);
	}
	X[M+1]=Y[M+1]=N;
	S[M].push_back(M);
	S[M].push_back(M+1);
	FOR(i,L) {
		j=i+M+2;
		cin>>X[j]>>Y[j];
		x=lower_bound(X,X+M+2,X[j])-X;
		if(X[x]==X[j]) {
			if(Y[x]==Y[j]) K--;
			if(Y[j]<Y[x]&&Y[x-1]<=Y[j]) S[x-1].push_back(j);
			if(Y[j]>Y[x]&&Y[j]<Y[x+1]) S[x].push_back(j);
		}
		else {
			if(Y[j]>=Y[x-1]&&Y[j]<=Y[x]) S[x-1].push_back(j);
		}
	}
	if(K<0) return _P("0\n");
	K=min(K,L);
	
	dp[0][K]=1;
	FOR(i,M+1) {
		vector<pair<int,int>> C;
		FORR(s,S[i]) C.push_back({X[s]+Y[s],s});
		sort(ALL(C));
		FOR(x,C.size()) FOR(y,C.size()) FOR(r,C.size()+1) pat[x][y][r]=0;
		FOR(x,C.size()) pat[x][x][0]=1;
		for(int len=1;len<=C.size();len++) {
			for(int f=0;f+len<C.size();f++) {
				int t=f+len;
				//direct
				int a=C[f].second;
				int b=C[t].second;
				if(X[a]>X[b]||Y[a]>Y[b]) continue;
				pat[f][t][1]=comb(Y[b]+X[b]-Y[a]-X[a],Y[b]-Y[a]);
				for(int m=f+1;m<t;m++) {
					int x=C[m].second;
					if(X[a]>X[x]||Y[a]>Y[x]) continue;
					if(X[x]>X[b]||Y[x]>Y[b]) continue;
					(pat[f][t][1]+=mo-pat[f][m][1]*comb(Y[b]+X[b]-Y[x]-X[x],Y[b]-Y[x])%mo)%=mo;
					for(j=1;j<=C.size()-1;j++) (pat[f][t][1+j]+=pat[f][m][1]*pat[m][t][j])%=mo;
				}
			}
		}
		FOR(x,101) for(y=1;y<=x+1;y++) (dp[i+1][x-(y-1)]+=dp[i][x]*pat[0][C.size()-1][y])%=mo;
	}
	
	ll ret=0;
	FOR(x,K+1) ret+=dp[M+1][x];
	cout<<ret%mo<<endl;	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0