QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#767818#8047. DFS Order 4ASnownAC ✓316ms6436kbC++174.1kb2024-11-20 22:15:342024-11-20 22:15:42

Judging History

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

  • [2024-11-20 22:15:42]
  • 评测
  • 测评结果:AC
  • 用时:316ms
  • 内存:6436kb
  • [2024-11-20 22:15:34]
  • 提交

answer

#include<bits/stdc++.h>
#define file(F) freopen(#F".in","r",stdin),freopen(#F".out","w",stdout)
#define lowbit(x) ((x)&-(x))
#define ALL(x) (x).begin(),(x).end()
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define popc(x) (__builtin_popcountll((x)))
#define abs(x) ((x)>=0?(x):-(x))
using namespace std;
using ll=long long;
using uint=uint32_t;
template<typename T>
inline bool Max(T &x,T y) { return std::less<T>()(x,y)&&(x=y,true); }
template<typename T>
inline bool Min(T &x,T y) { return std::less<T>()(y,x)&&(x=y,true); }
void Solve();
namespace asnown {
using i32=int32_t;
using u32=uint32_t;
using i64=int64_t;
using u64=uint64_t;
using i128=__int128_t;
using u128=__uint128_t;
struct barrett {
   u32 _m; u64 im;
   explicit barrett(u32 m) : _m(m),im((u64)(-1)/m+1) {}
   u32 umod() const { return _m; }
   u32 mul(u32 a,u32 b) const {
      u64 z=a; z*=b;
      u64 v=((u128(z)*im)>>64);
      u64 y=v*_m;
      return z-y+(z<y?_m:0);
   }
};
constexpr i32 inverse(i32 a,i32 m) {
   i64 r=1;
   while(a>1) { r=r*(m-m/a)%m,a=m%a; }
   return r;
}
template<i32 _m>
struct dynamic_modint {
   using mint=dynamic_modint;
public:
   constexpr dynamic_modint() : v(0) {}
   constexpr dynamic_modint(i32 v) : v(normal(v%mod())) {}
   constexpr dynamic_modint(u32 v) : v(v%mod()) {}
   constexpr dynamic_modint(i64 v) : v(normal(v%mod())) {}
   constexpr dynamic_modint(u64 v) : v(v%mod()) {}
   constexpr dynamic_modint(i128 v) : v(normal(v%mod())) {}
   constexpr dynamic_modint(u128 v) : v(v%mod()) {}
   constexpr static u32 normal(i32 v) { i32 m=mod(); if(v>=m) v-=m; return v+((v>>31)&m); }
   constexpr u32 val() const { return v; }
   constexpr static void set_mod(i32 m) { assert(m>=1); bt=barrett((u32)m); }
   constexpr static u32 mod() { return bt.umod(); }
   constexpr explicit operator bool() const { return v; }
   constexpr mint inv() const { assert(v!=0); return mint(inverse(v,mod())); }
   constexpr mint pow(i64 b) const { assert(b>=0); mint a=*this,res=1;
      for(;b;b>>=1,a*=a) if(b&1) res*=a; return res; }
   constexpr mint operator+() const { return *this; }
   constexpr mint operator-() const { return mint()-*this; }
   constexpr mint& operator+=(const mint &p) { return v=normal(v+p.v),*this; }
   constexpr mint& operator-=(const mint &p) { return v=normal(v-p.v),*this; }
   constexpr mint& operator++() { return (*this)+=1; }
   constexpr mint& operator--() { return (*this)-=1; }
   constexpr mint& operator++(i32) { auto tmp=*this; return ++*this,tmp; }
   constexpr mint& operator--(i32) { auto tmp=*this; return --*this,tmp; }
   constexpr mint& operator*=(const mint &p) { v=i64(v)*p.v%mod(); return *this; }
   constexpr mint& operator/=(const mint &p) { return *this *= p.inv(); }
   constexpr friend mint operator+(const mint &p,const mint &q) { return mint(p)+=q; }
   constexpr friend mint operator-(const mint &p,const mint &q) { return mint(p)-=q; }
   constexpr friend mint operator*(const mint &p,const mint &q) { return mint(p)*=q; }
   constexpr friend mint operator/(const mint &p,const mint &q) { return mint(p)/=q; }
   constexpr friend std::istream& operator>>(std::istream &is,mint &a) { i64 v; is>>v; a=v; return is; }
   constexpr friend std::ostream& operator<<(std::ostream &os,const mint &a) { os<<a.val(); return os; }
   constexpr bool operator==(const mint& p) const { return val()==p.val(); }
   constexpr bool operator!=(const mint& p) const { return val()!=p.val(); }
private:
   i32 v; 
   static barrett bt;
};
template<i32 m> barrett dynamic_modint<m>::bt(998244353);
using mint=dynamic_modint<-1>;
};
using asnown::mint;
const int N = 805;
int n,P;
mint f[N][N];
signed main() {
#ifndef ONLINE_JUDGE
#endif
   cin.tie(nullptr)->sync_with_stdio(false);
   Solve();
}
void Solve() {
   cin>>n>>P; mint::set_mod(P);
   f[1][0]=1;
   for(int i=2;i<=n;i++) for(int j=0;i+j<=n;j++) {
      f[i][j]=f[i-1][0];
      for(int k=2;k<=i-1;k++) f[i][j]+=f[i-k][j]*(f[k][0]-f[k][i-k-1+j]);
      f[i][j]/=i+j-1;
   }
   auto ans=f[n][0];
   for(int i=1;i<n;i++) ans*=i;
   printf("%d\n",ans.val());
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3816kb

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

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

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 247ms
memory: 6244kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 306ms
memory: 6436kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 269ms
memory: 6264kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 281ms
memory: 6196kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 265ms
memory: 6236kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 286ms
memory: 6212kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 314ms
memory: 6312kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 311ms
memory: 6248kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 269ms
memory: 6160kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 316ms
memory: 6324kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

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

input:

1 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

2 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #16:

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

input:

9 1009036033

output:

1780

result:

ok 1 number(s): "1780"

Test #17:

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

input:

14 1001338769

output:

43297358

result:

ok 1 number(s): "43297358"

Extra Test:

score: 0
Extra Test Passed