QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276672#7258. Random WalkPetroTarnavskyiAC ✓65ms160376kbC++201.8kb2023-12-06 03:47:432023-12-06 11:04:57

Judging History

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

  • [2023-12-06 11:04:57]
  • 管理员手动重测本题所有提交记录
  • 测评结果:AC
  • 用时:65ms
  • 内存:160376kb
  • [2023-12-06 03:47:43]
  • 评测
  • 测评结果:0
  • 用时:53ms
  • 内存:201820kb
  • [2023-12-06 03:47:43]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); i--)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

int mod;

int add(LL a, LL b)
{
	return a + b < mod ? a + b : a + b - mod;
}
void updAdd(LL& a, LL b)
{
	a += b;
	if(a >= mod)
		a -= mod;
}
void updSub(LL& a, LL b)
{
	a -= b;
	if(a < 0)
		a += mod;
}
int mult(int a, int b)
{
	return (LL)a * b % mod;
}
int binpow(int a, int n)
{
	int res = 1;
	while(n)
	{
		if(n & 1)
			res = mult(res, a);
		a = mult(a, a);
		n /= 2;
	}
	return res;
}

const int N = 5047;
LL f[N];
LL dp[N];
LL C[N][N];

int main()
{
	ios::sync_with_stdio(0); 
	cin.tie(0);
	cout << fixed << setprecision(15);
	int num;
	cin >> num >> mod;
	
	C[0][0] = 1;
	FOR(n, 1, N)
	{
		C[n][0] = 1;
		FOR(m, 1, n + 1)
		{
			C[n][m] = add(C[n - 1][m - 1], C[n - 1][m]);
		}
	}
	FOR(len, 0, N)
	{
		if(len % 2 == 1)
			continue;
		FOR(n, 0, len + 1)
		{
			if(n % 2 == 1)
				continue;
				
			int coef = 1;
			coef = mult(coef, C[len][n]);
			coef = mult(coef, C[n][n / 2]);
			coef = mult(coef, C[(len - n)][(len - n) / 2]);

			
			updAdd(f[len], coef);
		}
	}
	
	
	
	
	
	dp[0] = 1;
	FOR(n, 1, N)
	{
		dp[n] = binpow(4, n);
		FOR(when, 1, n + 1)
		{
			if(when % 2 == 1)
				continue;
			updSub(dp[n], mult(f[when], dp[n - when]));
		}
	}
	
	
	
	LL ans = 0;
	FOR(len, 0, num + 1)
	{
		updAdd(ans, mult(binpow(4, len), dp[num - len]));
	}
	cout << ans << "\n";





	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 52ms
memory: 160080kb

input:

2 1000000007

output:

44

result:

ok 1 number(s): "44"

Test #2:

score: 0
Accepted
time: 54ms
memory: 159904kb

input:

2015 2000000000

output:

1892319232

result:

ok 1 number(s): "1892319232"

Test #3:

score: 0
Accepted
time: 60ms
memory: 160332kb

input:

1 1335279264

output:

8

result:

ok 1 number(s): "8"

Test #4:

score: 0
Accepted
time: 60ms
memory: 159880kb

input:

2 1849598327

output:

44

result:

ok 1 number(s): "44"

Test #5:

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

input:

3 1822889311

output:

224

result:

ok 1 number(s): "224"

Test #6:

score: 0
Accepted
time: 51ms
memory: 160292kb

input:

4 1446755913

output:

1068

result:

ok 1 number(s): "1068"

Test #7:

score: 0
Accepted
time: 65ms
memory: 160032kb

input:

5 1526239859

output:

4960

result:

ok 1 number(s): "4960"

Test #8:

score: 0
Accepted
time: 57ms
memory: 158676kb

input:

4995 1548830120

output:

950970144

result:

ok 1 number(s): "950970144"

Test #9:

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

input:

4996 1181424399

output:

777518421

result:

ok 1 number(s): "777518421"

Test #10:

score: 0
Accepted
time: 58ms
memory: 157216kb

input:

4997 1715477619

output:

1422350413

result:

ok 1 number(s): "1422350413"

Test #11:

score: 0
Accepted
time: 56ms
memory: 157624kb

input:

4998 1342858071

output:

1282046306

result:

ok 1 number(s): "1282046306"

Test #12:

score: 0
Accepted
time: 58ms
memory: 157396kb

input:

4999 1625711486

output:

685405600

result:

ok 1 number(s): "685405600"

Test #13:

score: 0
Accepted
time: 56ms
memory: 157604kb

input:

5000 1448565595

output:

244248863

result:

ok 1 number(s): "244248863"

Test #14:

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

input:

4325 1647639160

output:

152052616

result:

ok 1 number(s): "152052616"

Test #15:

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

input:

4784 1449656269

output:

62584332

result:

ok 1 number(s): "62584332"

Test #16:

score: 0
Accepted
time: 56ms
memory: 155804kb

input:

2156 1336869678

output:

794572014

result:

ok 1 number(s): "794572014"

Test #17:

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

input:

902 1061020590

output:

502050782

result:

ok 1 number(s): "502050782"

Test #18:

score: 0
Accepted
time: 53ms
memory: 157568kb

input:

3537 1816372580

output:

304447408

result:

ok 1 number(s): "304447408"

Test #19:

score: 0
Accepted
time: 48ms
memory: 157380kb

input:

739 1389312924

output:

82391136

result:

ok 1 number(s): "82391136"

Test #20:

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

input:

4211 1547865075

output:

988813357

result:

ok 1 number(s): "988813357"

Test #21:

score: 0
Accepted
time: 56ms
memory: 157152kb

input:

3506 1605997004

output:

805360668

result:

ok 1 number(s): "805360668"

Test #22:

score: 0
Accepted
time: 58ms
memory: 157500kb

input:

1568 1539239436

output:

1103237896

result:

ok 1 number(s): "1103237896"

Test #23:

score: 0
Accepted
time: 51ms
memory: 157360kb

input:

16 1650693494

output:

334199630

result:

ok 1 number(s): "334199630"