QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#806523#7258. Random WalkInvincibleAC ✓76ms199312kbC++231.8kb2024-12-09 11:20:222024-12-09 11:20:22

Judging History

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

  • [2024-12-09 11:20:22]
  • 评测
  • 测评结果:AC
  • 用时:76ms
  • 内存:199312kb
  • [2024-12-09 11:20:22]
  • 提交

answer

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <ctime>
#include <random>
#include <cassert>
#include <numeric>
#include <cmath>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int, int>
#define fi first
#define se second
#define MP make_pair
#define ep emplace
#define eb emplace_back
#define int long long
#define rep(i, j, k) for (int i = (j); i <= (k); i++)
#define per(i, j, k) for (int i = (j); i >= (k); i--)
typedef double db;
typedef long double ldb;
typedef long long ll;
//typedef __int128 lll;
typedef unsigned long long ull;
typedef unsigned int ui;
using namespace std;
using namespace __gnu_pbds;
bool Mbe;

//char buf[1<<20],*p1,*p2;
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin), p1 == p2) ? 0 : *p1++)
int read() {
	int s = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9') f ^= (c == '-'), c = getchar();
	while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
	return f ? s : -s;
}
template<typename T>void chkmax(T&x,const T&y){if(x<y)x=y;}
template<typename T>void chkmin(T&x,const T&y){if(x>y)x=y;}

const int N=5005;
int n,mod,pw[N],ans,a[N],b[N],C[N][N],f[N];

bool Med;
signed main() {
	fprintf(stderr,"%.3lfMb\n",(&Mbe-&Med)/1024./1024.);
	n=read(),mod=read();
	pw[0]=1;
	rep(i,1,n)pw[i]=pw[i-1]*4%mod;
	rep(i,0,n){
		C[i][0]=1;
		rep(j,1,i)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
	rep(i,0,n/2){
		a[i]=C[i+i][i]*C[i+i][i]%mod;
		rep(j,1,i-1)a[i]=(a[i]-a[i-j]*C[j+j][j]%mod*C[j+j][j]%mod+mod)%mod;
	}
	f[0]=1;
	ans=pw[n];
	rep(i,1,n){
		if(i&1)f[i]=4*f[i-1]%mod;
		else f[i]=(4*f[i-1]-a[i/2]+mod)%mod;
		ans=(ans+pw[n-i]*f[i])%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 1000000007

output:

44

result:

ok 1 number(s): "44"

Test #2:

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

input:

2015 2000000000

output:

1892319232

result:

ok 1 number(s): "1892319232"

Test #3:

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

input:

1 1335279264

output:

8

result:

ok 1 number(s): "8"

Test #4:

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

input:

2 1849598327

output:

44

result:

ok 1 number(s): "44"

Test #5:

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

input:

3 1822889311

output:

224

result:

ok 1 number(s): "224"

Test #6:

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

input:

4 1446755913

output:

1068

result:

ok 1 number(s): "1068"

Test #7:

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

input:

5 1526239859

output:

4960

result:

ok 1 number(s): "4960"

Test #8:

score: 0
Accepted
time: 71ms
memory: 198680kb

input:

4995 1548830120

output:

950970144

result:

ok 1 number(s): "950970144"

Test #9:

score: 0
Accepted
time: 66ms
memory: 198080kb

input:

4996 1181424399

output:

777518421

result:

ok 1 number(s): "777518421"

Test #10:

score: 0
Accepted
time: 59ms
memory: 198720kb

input:

4997 1715477619

output:

1422350413

result:

ok 1 number(s): "1422350413"

Test #11:

score: 0
Accepted
time: 63ms
memory: 197720kb

input:

4998 1342858071

output:

1282046306

result:

ok 1 number(s): "1282046306"

Test #12:

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

input:

4999 1625711486

output:

685405600

result:

ok 1 number(s): "685405600"

Test #13:

score: 0
Accepted
time: 63ms
memory: 199312kb

input:

5000 1448565595

output:

244248863

result:

ok 1 number(s): "244248863"

Test #14:

score: 0
Accepted
time: 47ms
memory: 174048kb

input:

4325 1647639160

output:

152052616

result:

ok 1 number(s): "152052616"

Test #15:

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

input:

4784 1449656269

output:

62584332

result:

ok 1 number(s): "62584332"

Test #16:

score: 0
Accepted
time: 13ms
memory: 89992kb

input:

2156 1336869678

output:

794572014

result:

ok 1 number(s): "794572014"

Test #17:

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

input:

902 1061020590

output:

502050782

result:

ok 1 number(s): "502050782"

Test #18:

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

input:

3537 1816372580

output:

304447408

result:

ok 1 number(s): "304447408"

Test #19:

score: 0
Accepted
time: 6ms
memory: 32628kb

input:

739 1389312924

output:

82391136

result:

ok 1 number(s): "82391136"

Test #20:

score: 0
Accepted
time: 37ms
memory: 169884kb

input:

4211 1547865075

output:

988813357

result:

ok 1 number(s): "988813357"

Test #21:

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

input:

3506 1605997004

output:

805360668

result:

ok 1 number(s): "805360668"

Test #22:

score: 0
Accepted
time: 12ms
memory: 65540kb

input:

1568 1539239436

output:

1103237896

result:

ok 1 number(s): "1103237896"

Test #23:

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

input:

16 1650693494

output:

334199630

result:

ok 1 number(s): "334199630"