QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#87307#5747. Persian CasinorunewrzWA 17ms11360kbC++172.2kb2023-03-12 14:19:512023-03-12 14:19:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-12 14:19:52]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:11360kb
  • [2023-03-12 14:19:51]
  • 提交

answer

#include <bits/stdc++.h>

#define fo(i, x, y) for (int i = int(x); i <= int(y); ++i)
#define fd(i, x, y) for (int i = int(x); i >= int(y); --i)
#define fi first
#define se second

using namespace std;
using pii = pair<int, int>;
using i64 = long long;

constexpr int P = 1e9 + 9;
constexpr int N = 1e6 + 5;

template <class T>
T power(T a, int b)
{
	T res = 1;
	for (; b; b >>= 1, a *= a)
		if (b & 1)
			res *= a;
	return res;
}

int nor(int x)
{
	if (x < 0) x += P;
	if (x >= P) x -= P;
	return x;
}
struct Z
{
	int x;
	Z(i64 x = 0) : x(nor(x % P)) {}
	int val() const
	{
		return x;
	}
	Z operator-() const
	{
		return Z(nor(P - x));
	}
	Z inv() const
	{
		assert(x != 0);
		return power(*this, P - 2);
	}
	Z &operator*=(const Z &rhs)
	{
		x = i64(x) * rhs.x % P;
		return *this;
	}
	Z &operator+=(const Z &rhs)
	{
		x = nor(x + rhs.x);
		return *this;
	}
	Z &operator-=(const Z &rhs)
	{
		x = nor(x - rhs.x);
		return *this;
	}
	Z &operator/=(const Z &rhs)
	{
		return *this *= rhs.inv();
	}
	friend Z operator*(const Z &lhs, const Z &rhs)
	{
		Z res = lhs;
		res *= rhs;
		return res;
	}
	friend Z operator+(const Z &lhs, const Z &rhs)
	{
		Z res = lhs;
		res += rhs;
		return res;
	}
	friend Z operator-(const Z &lhs, const Z &rhs)
	{
		Z res = lhs;
		res -= rhs;
		return res;
	}
	friend Z operator/(const Z &lhs, const Z &rhs)
	{
		Z res = lhs;
		res /= rhs;
		return res;
	}
	friend istream& operator>>(istream& is, Z& a)
	{
		i64 v;
		is >> v;
		a = Z(v);
		return is;
	}
	friend ostream& operator<<(ostream& os, const Z& a)
	{
		return os << a.val();
	}
};

Z fac[N], ifac[N];

void init(int n)
{
	fac[0] = 1;
	fo(i, 1, n)
		fac[i] = fac[i - 1] * i;
	ifac[n] = 1 / fac[n];
	fd(i, n - 1, 0)
		ifac[i] = ifac[i + 1] * (i + 1);
}

Z C(int n, int m)
{
	return fac[n] * ifac[n - m] * ifac[m];
}

void work()
{
	int n, m;
	cin >> n >> m;
	i64 t = 1;
	bool ok = false;
	fo(i, 1, m)
	{
		t <<= 1;
		if (t >= n - m)
		{
			ok = true;
			break;
		}
	}
	if (!ok)
	{
		cout << "bankrupt\n";
		return;
	}
	Z ans = C(n, m);
	fo(i, 0, m - 1)
		ans += C(n, i);
	cout << ans << '\n';
}

int main()
{
	ios::sync_with_stdio(0), cin.tie(0);
#ifdef LC
	freopen("t.in", "r", stdin);
	freopen("t.out", "w", stdout);
#endif
	init(200000);
	int T;
	cin >> T;
	while (T--)
		work();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 11152kb

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: 7ms
memory: 11196kb

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
Wrong Answer
time: 17ms
memory: 11360kb

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:

wrong answer 4037th lines differ - expected: '262144', found: '480415224'