QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#527191#6323. Range NEQsolar_express#WA 44ms15972kbC++231.9kb2024-08-22 11:44:292024-08-22 11:44:30

Judging History

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

  • [2024-08-22 11:44:30]
  • 评测
  • 测评结果:WA
  • 用时:44ms
  • 内存:15972kb
  • [2024-08-22 11:44:29]
  • 提交

answer

#include <algorithm>
#include <cstdint>
#include <iostream>
const int N = 1<<19;
using namespace std;
using u64 = uint64_t;
const int mod = 998244353;
int rev[N], wn[N], lim, invlim;
int pow(int a, int b, int ans = 1) {
	for(;b;b >>= 1, a = (u64) a * a % mod) if(b & 1)
		ans = (u64) ans * a % mod;
	return ans;
}
void init(int len) {
	lim = 2 << std::__lg(len - 1);
	invlim = mod - (mod - 1) / lim;
	for(static int i = 1;i < lim;i += i) {
		wn[i] = 1;
		const int w = pow(3, mod / i / 2);
		for(int j = 1;j < i;++j) {
			wn[i + j] = (u64) wn[i + j - 1] * w % mod;
		}
	}
	for(int i = 1;i < lim;++i) {
		rev[i] = rev[i >> 1] >> 1 | (i % 2u * lim / 2);
	}
}
void DFT(int * a) {
	static u64 t[N];
	for(int i = 0;i < lim;++i) t[i] = a[rev[i]];
	for(int i = 1;i < lim;i += i) {
		for(int k = i & (1 << 19);k--;) 
			if(t[k] >= mod * 9ull) t[k] -= mod * 9ull;
		for(int j = 0;j < lim;j += i + i) {
			for(int k = 0;k < i;++k) {
				const u64 x = t[i + j + k] * wn[i + k] % mod;
				t[i + j + k] = t[k + j] + (mod - x), t[k + j] += x;
			}
		}
	}
	for(int i = 0;i < lim;++i) a[i] = t[i] % mod;
}
void IDFT(int * a) {
	DFT(a), std::reverse(a + 1, a + lim);
	for(int i = 0;i < lim;++i)
		a[i] = (u64) a[i] * invlim % mod;
}

int fac[N];
int pol[N];

int main() {
    int n, m;
    cin >> n >> m;
    fac[0] = 1;
    for (int i = 1; i <= m*n; ++i) fac[i] = 1ll*fac[i-1]*i % mod;
    for (int k = 0; k <= m; ++k) {
        int binom = pow(fac[k], mod-2, pow(fac[m-k], mod-2, fac[m]));
        pol[k] = 1ll * binom * binom % mod * fac[k] % mod;
        if (k & 1) pol[k] = (mod-pol[k]) % mod;
    }
    init(N);
    DFT(pol);
    for (int i = 0; i < lim; ++i) pol[i] = pow(pol[i], n);
    IDFT(pol);
    int ans = 0;
    for (int k = 0; k <= n*m; ++k) {
        ans = (ans + 1ll * pol[k] * fac[n*m-k]) % mod;
    }
    cout << ans << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 26ms
memory: 15968kb

input:

2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 27ms
memory: 15824kb

input:

5 1

output:

44

result:

ok 1 number(s): "44"

Test #3:

score: 0
Accepted
time: 30ms
memory: 15820kb

input:

167 91

output:

284830080

result:

ok 1 number(s): "284830080"

Test #4:

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

input:

2 1

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 26ms
memory: 15812kb

input:

2 3

output:

36

result:

ok 1 number(s): "36"

Test #6:

score: 0
Accepted
time: 27ms
memory: 15888kb

input:

2 4

output:

576

result:

ok 1 number(s): "576"

Test #7:

score: 0
Accepted
time: 19ms
memory: 15876kb

input:

3 1

output:

2

result:

ok 1 number(s): "2"

Test #8:

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

input:

3 2

output:

80

result:

ok 1 number(s): "80"

Test #9:

score: 0
Accepted
time: 28ms
memory: 15912kb

input:

3 3

output:

12096

result:

ok 1 number(s): "12096"

Test #10:

score: 0
Accepted
time: 26ms
memory: 15916kb

input:

3 4

output:

4783104

result:

ok 1 number(s): "4783104"

Test #11:

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

input:

4 1

output:

9

result:

ok 1 number(s): "9"

Test #12:

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

input:

4 2

output:

4752

result:

ok 1 number(s): "4752"

Test #13:

score: 0
Accepted
time: 18ms
memory: 15932kb

input:

4 3

output:

17927568

result:

ok 1 number(s): "17927568"

Test #14:

score: 0
Accepted
time: 26ms
memory: 15952kb

input:

4 4

output:

776703752

result:

ok 1 number(s): "776703752"

Test #15:

score: 0
Accepted
time: 21ms
memory: 15896kb

input:

5 2

output:

440192

result:

ok 1 number(s): "440192"

Test #16:

score: 0
Accepted
time: 26ms
memory: 15948kb

input:

5 3

output:

189125068

result:

ok 1 number(s): "189125068"

Test #17:

score: 0
Accepted
time: 28ms
memory: 15908kb

input:

5 4

output:

975434093

result:

ok 1 number(s): "975434093"

Test #18:

score: -100
Wrong Answer
time: 44ms
memory: 15876kb

input:

1000 1000

output:

151477183

result:

wrong answer 1st numbers differ - expected: '720037464', found: '151477183'