QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#226643#5747. Persian CasinopiaoyunTL 23ms23116kbC++201.8kb2023-10-26 12:11:292023-10-26 12:11:29

Judging History

你现在查看的是最新测评结果

  • [2023-10-26 12:11:29]
  • 评测
  • 测评结果:TL
  • 用时:23ms
  • 内存:23116kb
  • [2023-10-26 12:11:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define otto auto
const int MAXN=1e6+10;
const int INF=1ll*1e7*1e9;
const int MOD = 1e9 + 9;
int T,N,M,K,P,Q;


struct Math_class{
	static const int MAXN = 1e6 + 10;
	int fac[MAXN],facInv[MAXN];
	bool fac_ini = false;
	bool prime_ini = false;

	void getFac(int n = MAXN){
		fac_ini = true;
		fac[0] = 1;
		for(int i=1;i<n;i++) fac[i] = fac[i-1] * i % MOD;
		facInv[n-1] = inv(fac[n-1]);
		for(int i=n-2;i>=0;i--) facInv[i] = facInv[i+1] * (i+1) % MOD;
	}

	int C(int n,int m){
		assert(fac_ini);
		if(m > n || m < 0) return 0;
		return fac[n]*facInv[m]%MOD*facInv[n-m]%MOD;
	}
	int A(int n,int m){
		assert(fac_ini);
		if(m > n || m < 0) return 0;
		return fac[n]*facInv[n-m]%MOD;
	};

	bool is_prime[MAXN];
	vector<int> prime;
	void getPrime(int n = MAXN){
		prime_ini = true;
		for(int i=2;i<n;i++) is_prime[i] = true;
		for(int i=2;i<n;i++){
			if(is_prime[i]){
				prime.push_back(i);
				for(int j=2*i;j<n;j+=i) is_prime[j] = false;
			}
		}
	}

	int quick_pow(int x,int k){
		int ret = 1; x %= MOD;
		while(k){
			if(k&1) ret = ret * x % MOD;
			x = x * x % MOD; k >>= 1;
		}
		return ret;
	}
	int inv(int x){return quick_pow(x,MOD-2);}
}Math;

int p2[MAXN];

void prepare(){
	int ans = 0;
	scanf("%lld %lld",&N,&M);
	if(M <= 20 && p2[M] < N - M){
		printf("bankrupt\n");
		return;
	}
	for(int i = M;i <= N; i++){
		ans = (ans + Math.C(i-1,M-1)) % MOD;
	}
	for(int i = 0;i <= M-1; i++){
		ans = (ans + Math.C(N,i)) % MOD;
	}
	cout<<ans<<endl;
}

signed main(){
	//ios::sync_with_stdio(0);
	T=1;
	Math.getFac();
	p2[0] = 1;
	for(int i = 1;i <= 100000; i++) p2[i] = p2[i-1] * 2 % MOD;
	scanf("%lld",&T);
	while(T--){
	    prepare();
	}
	return 0;
}


詳細信息

Test #1:

score: 100
Accepted
time: 9ms
memory: 20996kb

input:

4
2 1
4 1
3 2
57639 34614

output:

3
bankrupt
7
869788168

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 23ms
memory: 23116kb

input:

16460
131 83
137 14
140 28
174 145
87 27
56 11
144 67
88 47
154 59
152 138
100 65
71 43
172 142
113 113
87 68
101 52
179 71
60 51
26 18
97 19
147 111
119 57
124 30
130 37
129 77
177 152
179 84
82 21
162 55
152 2
168 23
139 34
131 101
111 89
179 69
144 30
84 50
150 101
32 24
104 41
137 37
82 59
138 1...

output:

861401790
827411823
937669544
814872401
564368688
774329757
382020028
327399098
136919945
13075099
706031307
579851898
54033422
857164590
919274229
886008600
422741550
229676734
66137152
898506279
95608855
78287335
89291935
599857760
378517272
779874547
58872199
492901833
640116450
bankrupt
73638239...

result:

ok 16460 lines

Test #3:

score: -100
Time Limit Exceeded

input:

100000
40029 5
1295 16
50862 5
67072 8
51451 4
57967 7
40886 20
13278 1
61885 12
24790 1
80316 2
8554 8
49717 6
82652 8
83139 5
87135 16
7419 8
91357 12
28565 12
80411 1
83723 1
17818 2
36799 20
86016 7
56546 3
92119 10
46290 1
14836 14
63748 1
72859 1
1668 12
99713 23
65337 24
77683 11
36461 2
7810...

output:

bankrupt
670796506
bankrupt
bankrupt
bankrupt
bankrupt
563300247
bankrupt
bankrupt
bankrupt
bankrupt
bankrupt
bankrupt
bankrupt
bankrupt
bankrupt
bankrupt
bankrupt
bankrupt
bankrupt
bankrupt
bankrupt
58529615
bankrupt
bankrupt
bankrupt
bankrupt
402044100
bankrupt
bankrupt
966828094
574753812
1719404...

result: