Submission #3020503
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=3e3+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
T ans=0,f=1;
char ch=getchar();
while(!isdigit(ch)&&ch!='-')ch=getchar();
if(ch=='-')f=-1,ch=getchar();
while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
return ans*f;
}
template<typename T>void write(T x,char y)
{
if(x==0)
{
putchar('0'),putchar(y);
return;
}
if(x<0)
{
putchar('-');
x=-x;
}
static char wr[20];
int top=0;
for(;x;x/=10)wr[++top]=x%10+'0';
while(top)putchar(wr[top--]);
putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
freopen("E.in","r",stdin);
freopen("E.out","w",stdout);
#endif
}
int n,mo;
void input()
{
n=read<int>(),mo=read<int>();
}
int f[N][N];
ll power(ll x,int y,int Mod)
{
ll res=1;
for(;y;x=x*x%Mod,y>>=1)if(y&1)res=res*x%Mod;
return res;
}
int g[N];
int mc[N],inv[N];
ll C(int x,int y){return 1ll*mc[x]*inv[y]%mo*inv[x-y]%mo;}
ll cal(int i)
{
int res=0;
int x=power(2,n-i,mo-1);
x=power(2,x,mo);
For(j,0,i)res=(res+1ll*power(2,(n-i)*j,mo)*f[i][j]%mo)%mo;
return 1ll*x*res%mo;
}
void work()
{
f[0][0]=1;
For(i,1,n)
{
f[i][0]=1;
For(j,1,i)f[i][j]=(f[i-1][j-1]+1ll*f[i-1][j]*(j+1)%mo)%mo;
}
mc[0]=inv[0]=1;
For(i,1,n)mc[i]=1ll*mc[i-1]*i%mo;
inv[n]=power(mc[n],mo-2,mo);
Fordown(i,n-1,1)inv[i]=1ll*inv[i+1]*(i+1)%mo;
int ans=0;
For(i,0,n)
{
if(i&1)ans=(ans+mo-1ll*C(n,i)*cal(i)%mo)%mo;
else ans=(ans+1ll*C(n,i)*cal(i)%mo)%mo;
}
write(ans,'\n');
}
int main()
{
// file();
input();
work();
return 0;
}
Submission Info
Submission Time |
|
Task |
E - Everything on It |
User |
dengyixuan |
Language |
C++14 (GCC 5.4.1) |
Score |
900 |
Code Size |
1890 Byte |
Status |
AC |
Exec Time |
1837 ms |
Memory |
34176 KB |
Compile Error
./Main.cpp: In function ‘void file()’:
./Main.cpp:40:27: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
freopen("E.in","r",stdin);
^
./Main.cpp:41:29: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
freopen("E.out","w",stdout);
^
Judge Result
Set Name |
Sample |
Subtask1 |
Subtask2 |
Score / Max Score |
0 / 0 |
600 / 600 |
300 / 300 |
Status |
|
|
|
Set Name |
Test Cases |
Sample |
a01, a02, a03, a04 |
Subtask1 |
a01, a02, a03, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24 |
Subtask2 |
a01, a02, a03, a04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, c25, c26, c27, c28, c29, c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, c40, c41, c42, c43, c44 |
Case Name |
Status |
Exec Time |
Memory |
a01 |
AC |
1 ms |
256 KB |
a02 |
AC |
1 ms |
256 KB |
a03 |
AC |
1 ms |
512 KB |
a04 |
AC |
1828 ms |
34176 KB |
b05 |
AC |
1 ms |
256 KB |
b06 |
AC |
1 ms |
256 KB |
b07 |
AC |
1 ms |
256 KB |
b08 |
AC |
1 ms |
256 KB |
b09 |
AC |
1 ms |
256 KB |
b10 |
AC |
1 ms |
256 KB |
b11 |
AC |
1 ms |
256 KB |
b12 |
AC |
1 ms |
384 KB |
b13 |
AC |
1 ms |
384 KB |
b14 |
AC |
1 ms |
384 KB |
b15 |
AC |
1 ms |
384 KB |
b16 |
AC |
1 ms |
384 KB |
b17 |
AC |
1 ms |
384 KB |
b18 |
AC |
1 ms |
384 KB |
b19 |
AC |
1 ms |
384 KB |
b20 |
AC |
1 ms |
384 KB |
b21 |
AC |
1 ms |
512 KB |
b22 |
AC |
1 ms |
512 KB |
b23 |
AC |
1 ms |
512 KB |
b24 |
AC |
1 ms |
512 KB |
c25 |
AC |
1 ms |
512 KB |
c26 |
AC |
2 ms |
640 KB |
c27 |
AC |
4 ms |
896 KB |
c28 |
AC |
9 ms |
3072 KB |
c29 |
AC |
26 ms |
5120 KB |
c30 |
AC |
61 ms |
7168 KB |
c31 |
AC |
124 ms |
9216 KB |
c32 |
AC |
292 ms |
15360 KB |
c33 |
AC |
671 ms |
21504 KB |
c34 |
AC |
1276 ms |
29696 KB |
c35 |
AC |
1728 ms |
33792 KB |
c36 |
AC |
1780 ms |
33792 KB |
c37 |
AC |
1798 ms |
33920 KB |
c38 |
AC |
1811 ms |
34048 KB |
c39 |
AC |
1825 ms |
34176 KB |
c40 |
AC |
1827 ms |
34176 KB |
c41 |
AC |
1830 ms |
34176 KB |
c42 |
AC |
1833 ms |
34176 KB |
c43 |
AC |
1837 ms |
34176 KB |
c44 |
AC |
1828 ms |
34176 KB |