QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#446311 | #8047. DFS Order 4 | liuhengxi | AC ✓ | 46ms | 4040kb | C++14 | 1.6kb | 2024-06-17 07:23:27 | 2024-06-17 07:23:27 |
Judging History
answer
// created: Jun/16/2024 20:39:51
#include<cstdio>
#include<cctype>
#include<algorithm>
#define F(i,l,r) for(int i=(l),i##_end=(r);i<i##_end;++i)
#define I128 //||is_same<T,__int128_t>::value||is_same<T,__uint128_t>::value
using namespace std;
template<typename T>enable_if_t<is_integral<T>::value I128,void> readmain(T &x)
{
bool neg=false;int c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-')neg=true;
for(x=0;isdigit(c);c=getchar())x=(T)(10*x+(c-'0'));
if(neg)x=-x;
}
template<typename T>T& read(T &x){readmain(x);return x;}
template<typename T,typename ...Tr>void read(T &x,Tr&... r){readmain(x);read(r...);}
typedef unsigned long long ull;
typedef __uint128_t u128;
struct barrett
{
ull mod,inv;
void init(int mod_){inv=(-1ull)/(mod=mod_)+1;}
int operator()(ull x)
{
x-=(ull)((u128)x*inv>>64)*mod;
if(x>>63)x+=mod;
return (int)x;
}
};
constexpr int N=805;
int mod;barrett bar;
void reduce(int &x){(x>=mod)&&(x-=mod);}
void reduce_(int &x){(x<0)&&(x+=mod);}
int n,inv[N],f[N],g[N][N];
ull t[N];
int main()
{
read(n,mod);bar.init(mod);
inv[1]=1;
F(i,2,n+1)inv[i]=bar((ull)(mod-mod/i)*inv[mod%i]);
F(i,1,n+1)
{
f[i]=g[i-1][0]+(i==1);
F(j,0,i)t[j]=0;
t[0]=f[i];
F(j,1,i-1)
{
t[0]+=(ull)f[i-j]*g[j][0];
F(k,1,min(j+1,n-i))t[k]+=(ull)f[i-j]*(g[j][k]-g[j][k-1]+mod);
if(!(j&7))F(k,0,min(j+1,n-i))t[k]=bar(t[k]);
}
F(j,0,i)g[i][j]=bar(t[j]);
F(j,0,i-1)reduce_(g[i][j+1]-=g[i-1][j]);
F(j,1,i-1)reduce(g[i][j-1]+=g[i-1][j]);
F(j,0,i)g[i][j]=bar((ull)inv[i]*g[i][j]);
}
int ans=f[n];
F(i,1,n)ans=bar((ull)i*ans);
printf("%d\n",ans);
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 1508kb
input:
4 114514199
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 1552kb
input:
10 998244353
output:
11033
result:
ok 1 number(s): "11033"
Test #3:
score: 0
Accepted
time: 0ms
memory: 1828kb
input:
100 1000000007
output:
270904395
result:
ok 1 number(s): "270904395"
Test #4:
score: 0
Accepted
time: 39ms
memory: 3904kb
input:
756 1001338769
output:
901942543
result:
ok 1 number(s): "901942543"
Test #5:
score: 0
Accepted
time: 44ms
memory: 4016kb
input:
793 1009036033
output:
301770320
result:
ok 1 number(s): "301770320"
Test #6:
score: 0
Accepted
time: 39ms
memory: 3880kb
input:
759 1005587659
output:
846376219
result:
ok 1 number(s): "846376219"
Test #7:
score: 0
Accepted
time: 41ms
memory: 3972kb
input:
773 1007855479
output:
1398019
result:
ok 1 number(s): "1398019"
Test #8:
score: 0
Accepted
time: 38ms
memory: 3884kb
input:
751 1006730639
output:
321287237
result:
ok 1 number(s): "321287237"
Test #9:
score: 0
Accepted
time: 43ms
memory: 3948kb
input:
778 1007760653
output:
430322899
result:
ok 1 number(s): "430322899"
Test #10:
score: 0
Accepted
time: 45ms
memory: 4036kb
input:
798 1007543827
output:
688720826
result:
ok 1 number(s): "688720826"
Test #11:
score: 0
Accepted
time: 46ms
memory: 4024kb
input:
796 1004841413
output:
258829347
result:
ok 1 number(s): "258829347"
Test #12:
score: 0
Accepted
time: 42ms
memory: 3972kb
input:
775 1005185189
output:
744278608
result:
ok 1 number(s): "744278608"
Test #13:
score: 0
Accepted
time: 46ms
memory: 4040kb
input:
800 1006012831
output:
508549367
result:
ok 1 number(s): "508549367"
Test #14:
score: 0
Accepted
time: 0ms
memory: 1536kb
input:
1 1001338769
output:
1
result:
ok 1 number(s): "1"
Test #15:
score: 0
Accepted
time: 0ms
memory: 1528kb
input:
2 1001338769
output:
1
result:
ok 1 number(s): "1"
Test #16:
score: 0
Accepted
time: 0ms
memory: 1512kb
input:
9 1009036033
output:
1780
result:
ok 1 number(s): "1780"
Test #17:
score: 0
Accepted
time: 0ms
memory: 1476kb
input:
14 1001338769
output:
43297358
result:
ok 1 number(s): "43297358"
Extra Test:
score: 0
Extra Test Passed