Submission #114109

#TimeUsernameProblemLanguageResultExecution timeMemory
114109shayan_pAsceticism (JOI18_asceticism)C++14
49 / 100
1068 ms1368 KiB
// High above the clouds there is a rainbow... #include<bits/stdc++.h> #define F first #define S second #define PB push_back #define sz(s) int((s).size()) #define bit(n,k) (((n)>>(k))&1) using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int maxn=1e5+10,mod=1e9+7; const ll inf=1e18; int dp[maxn],fac[maxn],ifac[maxn],dp2[maxn]; int Pow(int a,int b){ int ans=1; for(;b;b>>=1,a=1ll*a*a %mod){ if(b&1) ans=1ll*ans*a %mod; } return ans; } int C(int n,int k){ return 1ll*fac[n] * ifac[k] %mod *ifac[n-k] %mod; } int main(){ ios_base::sync_with_stdio(false);cin.tie(0); fac[0]=1; for(int i=1;i<maxn;i++) fac[i]=1ll*i*fac[i-1] %mod; ifac[maxn-1]=Pow(fac[maxn-1],mod-2); for(int i=maxn-2;i>=0;i--) ifac[i]=1ll*(i+1)*ifac[i+1] %mod; int n,k;cin>>n>>k; for(int i=1;i<=k;i++){ dp2[i]=1ll*Pow(i,n); for(int j=1;j<i;j++) dp2[i]=(dp2[i]-1ll*dp2[j]*C(i,j))%mod; dp[i]=dp2[i]; for(int j=1;j<i;j++) dp[i]=(dp[i]-1ll*dp[j]*C(n-j,i-j))%mod; } if(dp[k]<0) dp[k]+=mod; return cout<<dp[k]<<endl,0; } // Deathly mistakes: // * Read the problem curfully. // * Check maxn. // * Overflows.
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...