QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#53883#4843. Infectious Diseasezhoukangyang#AC ✓1217ms167860kbC++111.5kb2022-10-06 10:03:202022-10-06 10:03:22

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-06 10:03:22]
  • 评测
  • 测评结果:AC
  • 用时:1217ms
  • 内存:167860kb
  • [2022-10-06 10:03:20]
  • 提交

answer

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define sz(a) ((int) (a).size())
#define vi vector < int > 
#define me(a, x) memset(a, x, sizeof(a))
#define ull unsigned long long
#define ld __float128
using namespace std;
const int N = 1.4e7 + 7, mod = 1e9 + 7;
int qpow(int x, int y = mod - 2) {
	int res = 1;
	for(; y; x = (ll) x * x % mod, y >>= 1) if(y & 1) res = (ll) res * x % mod;
	return res;
}
int fac[N], ifac[N], inv[N];
void init(int x) {
	fac[0] = ifac[0] = inv[1] = 1;
	L(i, 2, x) inv[i] = (ll) (mod - mod / i) * inv[mod % i] % mod;
	L(i, 1, x) fac[i] = (ll) fac[i - 1] * i % mod, ifac[i] = (ll) ifac[i - 1] * inv[i] % mod;
} 
int C(int x, int y) {
	return x < y || y < 0 ? 0 : (ll) fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
int n, m, a[N];
string s;
int dp[N], xdp[N], tk;
int main() {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n, init(n);
	dp[1] = 1, tk = 1;
	int ns = 1;
	for(int k = 3; k <= n; k *= 3) {
		R(i, tk, 1) dp[i * 2] = dp[i], dp[i] = 0; 
		dp[0] = 0, tk *= 2; 
		int lst = k / 3, cp = k - lst;
		L(i, 0, tk) xdp[i] = 0;
		R(i, tk, 0) if(dp[i]) {
			dp[i] = (ll) dp[i] * qpow(C(n - lst, cp)) % mod;
			L(j, 0, i) 
				(xdp[i - j] += (ll) dp[i] * C(i, j) % mod * C(n - lst - i, cp - j) % mod) %= mod;
		}
		L(i, 1, tk) dp[i] = xdp[i], (ns += dp[i]) %= mod;
		dp[0] = 0;
	}
	cout << ns << '\n';
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3656kb

input:

2

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3596kb

input:

114

output:

505208013

result:

ok 1 number(s): "505208013"

Test #3:

score: 0
Accepted
time: 1217ms
memory: 167860kb

input:

14000000

output:

44565093

result:

ok 1 number(s): "44565093"

Test #4:

score: 0
Accepted
time: 1189ms
memory: 148496kb

input:

12345678

output:

123143093

result:

ok 1 number(s): "123143093"

Test #5:

score: 0
Accepted
time: 73ms
memory: 12620kb

input:

776777

output:

764022068

result:

ok 1 number(s): "764022068"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3688kb

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

4

output:

666666673

result:

ok 1 number(s): "666666673"

Test #8:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

5

output:

833333341

result:

ok 1 number(s): "833333341"

Test #9:

score: 0
Accepted
time: 2ms
memory: 3604kb

input:

6

output:

300000004

result:

ok 1 number(s): "300000004"

Test #10:

score: 0
Accepted
time: 2ms
memory: 3716kb

input:

7

output:

533333339

result:

ok 1 number(s): "533333339"

Test #11:

score: 0
Accepted
time: 2ms
memory: 3608kb

input:

8

output:

952380961

result:

ok 1 number(s): "952380961"

Test #12:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

9

output:

964285723

result:

ok 1 number(s): "964285723"

Test #13:

score: 0
Accepted
time: 2ms
memory: 3688kb

input:

10

output:

416666672

result:

ok 1 number(s): "416666672"

Test #14:

score: 0
Accepted
time: 2ms
memory: 3760kb

input:

26

output:

990086590

result:

ok 1 number(s): "990086590"

Test #15:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

27

output:

528360342

result:

ok 1 number(s): "528360342"

Test #16:

score: 0
Accepted
time: 2ms
memory: 3660kb

input:

28

output:

273239648

result:

ok 1 number(s): "273239648"

Test #17:

score: 0
Accepted
time: 312ms
memory: 59772kb

input:

4782967

output:

332194401

result:

ok 1 number(s): "332194401"

Test #18:

score: 0
Accepted
time: 310ms
memory: 59768kb

input:

4782968

output:

362625027

result:

ok 1 number(s): "362625027"

Test #19:

score: 0
Accepted
time: 414ms
memory: 59896kb

input:

4782969

output:

971032452

result:

ok 1 number(s): "971032452"

Test #20:

score: 0
Accepted
time: 396ms
memory: 59840kb

input:

4782970

output:

452836984

result:

ok 1 number(s): "452836984"

Test #21:

score: 0
Accepted
time: 427ms
memory: 59664kb

input:

4782971

output:

349324970

result:

ok 1 number(s): "349324970"

Test #22:

score: 0
Accepted
time: 410ms
memory: 59668kb

input:

4782972

output:

46862963

result:

ok 1 number(s): "46862963"

Test #23:

score: 0
Accepted
time: 4ms
memory: 4968kb

input:

114514

output:

972669965

result:

ok 1 number(s): "972669965"

Test #24:

score: 0
Accepted
time: 257ms
memory: 26176kb

input:

1919810

output:

482430785

result:

ok 1 number(s): "482430785"

Test #25:

score: 0
Accepted
time: 1098ms
memory: 107712kb

input:

8877877

output:

486769120

result:

ok 1 number(s): "486769120"