QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#308201 | #8015. 鸡 | Crysfly | 100 ✓ | 1ms | 5768kb | C++17 | 3.5kb | 2024-01-19 18:28:29 | 2024-01-19 18:28:30 |
Judging History
answer
// 如何不分析性质,暴力通过这道题
// what is matter? never mind.
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
//#define ull unsigned long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
int mod;
typedef unsigned long long ull;
namespace FM{
typedef __uint128_t L;
struct FastMod{
ull b,m;
FastMod(ull b):b(b),m(ull((L(1)<<64)/b)){}
ull reduce(ull a){ull q=(ull)((L(m)*a)>>64),r=a-q*b;return r>=b?r-b:r;}
};
FastMod F(2);
}
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=FM::F.reduce(1ull*x*o.x),*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,int b){return a.x==b;}
friend bool operator !=(modint a,int b){return a.x!=b;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
void initmod(){mod=read(),FM::F=FM::FastMod(mod);}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 500005
#define inf 0x3f3f3f3f
//(2,2m,-2m-2,-m*m-2m+1,2m,m*m)
int n;
modint m;
modint f[maxn];
int tab[12][12]={
{1},
{1},
{1,4,9,16,25},
{1,6,17,36,65,106},
{1,12,47,120,245,436,707},
{1,19,94,281,649,1281,2274,3739},
{1,35,227,803,2089,4511,8595,14967,24353},
{1,58,477,1960,5705,13506,27853,52032,90225}
};
struct fval{
vector<modint>x,y;
void ins(modint X,modint Y){x.pb(X),y.pb(Y);}
void init(){x.clear(),y.clear();}
modint val(modint k){
int n=x.size();
modint res=0;
For(i,0,n-1){
modint s1=1,s2=1;
For(j,0,n-1)if(i!=j)s1*=(k-x[j]),s2*=(x[i]-x[j]);
res+=y[i]*s1/s2;
}
return res;
}
}F;
signed main()
{
n=read(),m=read(),initmod();
For(i,2,7){
F.init();
For(j,0,i)F.ins(j,tab[i][j]%mod);
f[i]=F.val(m);
}
For(i,8,n)f[i]=f[i-1]*2+f[i-2]*2*m+f[i-3]*((-m)*2-2)+f[i-4]*((-m)*m-m*2+1)+f[i-5]*m*2+f[i-6]*m*m;
cout<<f[n].x;
return 0;
}
/*
*/
详细
Test #1:
score: 5
Accepted
time: 1ms
memory: 5692kb
input:
5 5 1004326439
output:
1281
result:
ok 1 number(s): "1281"
Test #2:
score: 5
Accepted
time: 0ms
memory: 5768kb
input:
5 4 1002682123
output:
649
result:
ok 1 number(s): "649"
Test #3:
score: 5
Accepted
time: 0ms
memory: 5552kb
input:
287 1 1003060133
output:
328406329
result:
ok 1 number(s): "328406329"
Test #4:
score: 5
Accepted
time: 0ms
memory: 5536kb
input:
279 1 1004432189
output:
222258837
result:
ok 1 number(s): "222258837"
Test #5:
score: 5
Accepted
time: 0ms
memory: 5760kb
input:
300 1 1005912203
output:
707086810
result:
ok 1 number(s): "707086810"
Test #6:
score: 5
Accepted
time: 1ms
memory: 5536kb
input:
288 5 1003307827
output:
964512417
result:
ok 1 number(s): "964512417"
Test #7:
score: 5
Accepted
time: 0ms
memory: 5752kb
input:
281 5 1008854383
output:
755282155
result:
ok 1 number(s): "755282155"
Test #8:
score: 5
Accepted
time: 0ms
memory: 5528kb
input:
270 5 1007619367
output:
431828317
result:
ok 1 number(s): "431828317"
Test #9:
score: 5
Accepted
time: 0ms
memory: 5552kb
input:
292 5 1002449813
output:
183613546
result:
ok 1 number(s): "183613546"
Test #10:
score: 5
Accepted
time: 1ms
memory: 5752kb
input:
300 5 1005897091
output:
915308166
result:
ok 1 number(s): "915308166"
Test #11:
score: 5
Accepted
time: 0ms
memory: 5688kb
input:
45 50 1009100993
output:
940158800
result:
ok 1 number(s): "940158800"
Test #12:
score: 5
Accepted
time: 1ms
memory: 5556kb
input:
49 50 1001428049
output:
1045902
result:
ok 1 number(s): "1045902"
Test #13:
score: 5
Accepted
time: 1ms
memory: 5548kb
input:
49 50 1007851073
output:
922264698
result:
ok 1 number(s): "922264698"
Test #14:
score: 5
Accepted
time: 1ms
memory: 5752kb
input:
50 50 1005625571
output:
442192770
result:
ok 1 number(s): "442192770"
Test #15:
score: 5
Accepted
time: 1ms
memory: 5516kb
input:
290 300 1005068699
output:
484359497
result:
ok 1 number(s): "484359497"
Test #16:
score: 5
Accepted
time: 1ms
memory: 5692kb
input:
270 300 1003440637
output:
899894137
result:
ok 1 number(s): "899894137"
Test #17:
score: 5
Accepted
time: 1ms
memory: 5424kb
input:
300 300 1008561979
output:
33407754
result:
ok 1 number(s): "33407754"
Test #18:
score: 5
Accepted
time: 1ms
memory: 5684kb
input:
2991 3000 1004658859
output:
167444547
result:
ok 1 number(s): "167444547"
Test #19:
score: 5
Accepted
time: 0ms
memory: 5464kb
input:
2870 3000 1004054173
output:
860666062
result:
ok 1 number(s): "860666062"
Test #20:
score: 5
Accepted
time: 1ms
memory: 5552kb
input:
3000 3000 1009539589
output:
696222334
result:
ok 1 number(s): "696222334"