QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#320451#8211. Enumerating Substringsucup-team2303#AC ✓143ms75572kbC++112.2kb2024-02-03 17:01:282024-02-03 17:01:29

Judging History

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

  • [2024-02-03 17:01:29]
  • 评测
  • 测评结果:AC
  • 用时:143ms
  • 内存:75572kb
  • [2024-02-03 17:01:28]
  • 提交

answer

/*
60 + 0 + 100 + 64 = 224.
*/

#include <bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
#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 pb push_back
#define pii pair<int, int>
inline int read()
{
	int sum = 0, nega = 1;
	char ch = getchar();
	while (ch > '9'||ch < '0')
	{
	    if (ch == '-') nega = -1;
		ch = getchar();
	}
	while (ch <= '9' && ch >= '0') sum = sum * 10 + ch - '0', ch = getchar();
	return sum * nega;
}
const int N = 4009, M = 2e6 + 9, mod = 1e9 + 7, inv2 = (mod + 1) / 2;
inline void add(int &x, int y) {x = (x + y) % mod;}
inline void del(int &x, int y) {x = (x - y + mod) % mod;}
inline int Pow(int x, int y) 
{
	int res = 1, base = x % mod;
	while(y) 
	{
		if(y & 1) res = res * base % mod;
		base = base * base % mod; y >>= 1; 
	} return res; 
}
int tt[N]; 
int n, m, k, ans, C[N][N], jc[N], nw, pown[M]; 
inline int f(int x, int y) 
{
	if(x == 0 && y == 0) return 1;
	if(y <= (x - 1) / 2) return 0;
	if(y <= 0) return 0; 
	int res = 0; 
	tt[0] = 1; 
	L(i, 1, x) tt[i] = tt[i - 1] * (y - i + 1) % mod * Pow(i, mod - 2) % mod;  
	L(i, 0, x / 2) 
	{
		int tmp = tt[x - i] * C[x - i][i] % mod; 
		tmp = tmp * jc[x] % mod; tmp = tmp * Pow(inv2, i) % mod;
		res = (res + tmp) % mod;  
	}
	return res; 
}
signed main()
{
	n = read(), m = read(), k = read(); pown[0] = 1; 
	L(i, 1, n) pown[i] = pown[i - 1] * k % mod; 
	L(i, 0, m) C[i][i] = C[i][0] = 1;
	jc[0] = 1;
	L(i, 1, m) jc[i] = jc[i - 1] * i % mod;  
	L(i, 1, m) 
		L(j, 1, i - 1) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod; 
	ans = (ans + f(m, k) * Pow(k, n - m) % mod * (n - m + 1) % mod) % mod; 
	nw = 1; 
	L(i, 1, m / 2) 
	{
		nw = nw * (k - i + 1) % mod;
		int tt = f(m - i * 2, k - i) * nw % mod, sum = 0; 
		L(j, 2, 1e9) 
		{
			int w = m + (m - i) * (j - 1); 
			if(w > n) break; 
			if(j % 2 == 0) sum = (sum - pown[n - w] * (n - w + 1) % mod + mod) % mod; 
			else sum = (sum + pown[n - w] * (n - w + 1) % mod) % mod; 
		}
		ans = (ans + sum * tt % mod) % mod; 
	}
	ans = (ans % mod + mod) % mod; 
	cout << ans << endl; 
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5768kb

input:

4 2 3

output:

228

result:

ok 1 number(s): "228"

Test #2:

score: 0
Accepted
time: 143ms
memory: 75572kb

input:

999999 1999 12345678

output:

52352722

result:

ok 1 number(s): "52352722"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5592kb

input:

7 4 2

output:

182

result:

ok 1 number(s): "182"

Test #4:

score: 0
Accepted
time: 1ms
memory: 5772kb

input:

4 3 4

output:

480

result:

ok 1 number(s): "480"

Test #5:

score: 0
Accepted
time: 1ms
memory: 5644kb

input:

3 1 1

output:

3

result:

ok 1 number(s): "3"

Test #6:

score: 0
Accepted
time: 1ms
memory: 5652kb

input:

5 5 1

output:

0

result:

ok 1 number(s): "0"

Test #7:

score: 0
Accepted
time: 1ms
memory: 5732kb

input:

7 4 3

output:

5784

result:

ok 1 number(s): "5784"

Test #8:

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

input:

5 2 4

output:

3932

result:

ok 1 number(s): "3932"

Test #9:

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

input:

8 2 2

output:

1522

result:

ok 1 number(s): "1522"

Test #10:

score: 0
Accepted
time: 1ms
memory: 5636kb

input:

8 1 2

output:

2048

result:

ok 1 number(s): "2048"

Test #11:

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

input:

7 5 3

output:

2430

result:

ok 1 number(s): "2430"

Test #12:

score: 0
Accepted
time: 1ms
memory: 5596kb

input:

10 4 3

output:

272004

result:

ok 1 number(s): "272004"

Test #13:

score: 0
Accepted
time: 9ms
memory: 31720kb

input:

675978 614 2

output:

0

result:

ok 1 number(s): "0"

Test #14:

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

input:

244613 38 1

output:

0

result:

ok 1 number(s): "0"

Test #15:

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

input:

186293 1462 1

output:

0

result:

ok 1 number(s): "0"

Test #16:

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

input:

24867 886 1

output:

0

result:

ok 1 number(s): "0"

Test #17:

score: 0
Accepted
time: 14ms
memory: 45792kb

input:

976164 1014 2

output:

0

result:

ok 1 number(s): "0"

Test #18:

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

input:

179356 2 716844809

output:

577866092

result:

ok 1 number(s): "577866092"

Test #19:

score: 0
Accepted
time: 3ms
memory: 15736kb

input:

621001 130 310625363

output:

892869197

result:

ok 1 number(s): "892869197"

Test #20:

score: 0
Accepted
time: 35ms
memory: 39540kb

input:

678862 850 754662812

output:

582264789

result:

ok 1 number(s): "582264789"

Test #21:

score: 0
Accepted
time: 42ms
memory: 41656kb

input:

650845 978 348443366

output:

825425732

result:

ok 1 number(s): "825425732"

Test #22:

score: 0
Accepted
time: 10ms
memory: 23832kb

input:

669914 402 87448112

output:

318098088

result:

ok 1 number(s): "318098088"

Test #23:

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

input:

998593 530 681228665

output:

408255654

result:

ok 1 number(s): "408255654"

Test #24:

score: 0
Accepted
time: 124ms
memory: 70612kb

input:

369361 1954 125266115

output:

509912384

result:

ok 1 number(s): "509912384"

Test #25:

score: 0
Accepted
time: 76ms
memory: 57096kb

input:

900226 1378 424079373

output:

406320917

result:

ok 1 number(s): "406320917"

Test #26:

score: 0
Accepted
time: 79ms
memory: 56304kb

input:

334887 1506 17859926

output:

503264679

result:

ok 1 number(s): "503264679"

Test #27:

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

input:

936048 544 53978328

output:

548647866

result:

ok 1 number(s): "548647866"

Test #28:

score: 0
Accepted
time: 52ms
memory: 47632kb

input:

152789 1264 792983073

output:

839541707

result:

ok 1 number(s): "839541707"

Test #29:

score: 0
Accepted
time: 72ms
memory: 56632kb

input:

714493 1392 91796331

output:

721071046

result:

ok 1 number(s): "721071046"

Test #30:

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

input:

269571 816 830801077

output:

330064211

result:

ok 1 number(s): "330064211"

Test #31:

score: 0
Accepted
time: 38ms
memory: 42864kb

input:

845120 944 424581630

output:

348960190

result:

ok 1 number(s): "348960190"

Test #32:

score: 0
Accepted
time: 3ms
memory: 21316kb

input:

533990 368 163586376

output:

522092095

result:

ok 1 number(s): "522092095"

Test #33:

score: 0
Accepted
time: 101ms
memory: 64408kb

input:

181707 1792 462399634

output:

373795106

result:

ok 1 number(s): "373795106"

Test #34:

score: 0
Accepted
time: 120ms
memory: 69480kb

input:

417349 1920 761212891

output:

587051329

result:

ok 1 number(s): "587051329"

Test #35:

score: 0
Accepted
time: 64ms
memory: 51644kb

input:

526583 1344 500217637

output:

108767800

result:

ok 1 number(s): "108767800"

Test #36:

score: 0
Accepted
time: 32ms
memory: 38924kb

input:

867054 769 93998191

output:

239123369

result:

ok 1 number(s): "239123369"

Extra Test:

score: 0
Extra Test Passed