답안 #114109

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
114109 2019-05-30T11:23:24 Z shayan_p Asceticism (JOI18_asceticism) C++14
49 / 100
600 ms 1368 KB
// 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.
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1152 KB Output is correct
2 Correct 4 ms 1152 KB Output is correct
3 Correct 4 ms 1152 KB Output is correct
4 Correct 4 ms 1152 KB Output is correct
5 Correct 4 ms 1152 KB Output is correct
6 Correct 4 ms 1152 KB Output is correct
7 Correct 4 ms 1152 KB Output is correct
8 Correct 4 ms 1068 KB Output is correct
9 Correct 4 ms 1152 KB Output is correct
10 Correct 4 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1152 KB Output is correct
2 Correct 4 ms 1152 KB Output is correct
3 Correct 4 ms 1152 KB Output is correct
4 Correct 4 ms 1152 KB Output is correct
5 Correct 4 ms 1152 KB Output is correct
6 Correct 4 ms 1152 KB Output is correct
7 Correct 4 ms 1152 KB Output is correct
8 Correct 4 ms 1068 KB Output is correct
9 Correct 4 ms 1152 KB Output is correct
10 Correct 4 ms 1152 KB Output is correct
11 Correct 4 ms 1152 KB Output is correct
12 Correct 4 ms 1152 KB Output is correct
13 Correct 4 ms 1152 KB Output is correct
14 Correct 4 ms 1152 KB Output is correct
15 Correct 5 ms 1152 KB Output is correct
16 Correct 5 ms 1152 KB Output is correct
17 Correct 4 ms 1152 KB Output is correct
18 Correct 4 ms 1152 KB Output is correct
19 Correct 4 ms 1152 KB Output is correct
20 Correct 4 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1152 KB Output is correct
2 Correct 4 ms 1152 KB Output is correct
3 Correct 4 ms 1152 KB Output is correct
4 Correct 4 ms 1152 KB Output is correct
5 Correct 4 ms 1152 KB Output is correct
6 Correct 4 ms 1152 KB Output is correct
7 Correct 4 ms 1152 KB Output is correct
8 Correct 4 ms 1068 KB Output is correct
9 Correct 4 ms 1152 KB Output is correct
10 Correct 4 ms 1152 KB Output is correct
11 Correct 4 ms 1152 KB Output is correct
12 Correct 4 ms 1152 KB Output is correct
13 Correct 4 ms 1152 KB Output is correct
14 Correct 4 ms 1152 KB Output is correct
15 Correct 5 ms 1152 KB Output is correct
16 Correct 5 ms 1152 KB Output is correct
17 Correct 4 ms 1152 KB Output is correct
18 Correct 4 ms 1152 KB Output is correct
19 Correct 4 ms 1152 KB Output is correct
20 Correct 4 ms 1152 KB Output is correct
21 Correct 3 ms 1152 KB Output is correct
22 Correct 4 ms 1152 KB Output is correct
23 Correct 5 ms 1152 KB Output is correct
24 Correct 5 ms 1152 KB Output is correct
25 Correct 9 ms 1212 KB Output is correct
26 Correct 10 ms 1152 KB Output is correct
27 Correct 10 ms 1152 KB Output is correct
28 Correct 6 ms 1152 KB Output is correct
29 Correct 4 ms 1152 KB Output is correct
30 Correct 10 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1152 KB Output is correct
2 Correct 4 ms 1152 KB Output is correct
3 Correct 4 ms 1152 KB Output is correct
4 Correct 4 ms 1152 KB Output is correct
5 Correct 4 ms 1152 KB Output is correct
6 Correct 4 ms 1152 KB Output is correct
7 Correct 4 ms 1152 KB Output is correct
8 Correct 4 ms 1068 KB Output is correct
9 Correct 4 ms 1152 KB Output is correct
10 Correct 4 ms 1152 KB Output is correct
11 Correct 4 ms 1152 KB Output is correct
12 Correct 4 ms 1152 KB Output is correct
13 Correct 4 ms 1152 KB Output is correct
14 Correct 4 ms 1152 KB Output is correct
15 Correct 5 ms 1152 KB Output is correct
16 Correct 5 ms 1152 KB Output is correct
17 Correct 4 ms 1152 KB Output is correct
18 Correct 4 ms 1152 KB Output is correct
19 Correct 4 ms 1152 KB Output is correct
20 Correct 4 ms 1152 KB Output is correct
21 Correct 3 ms 1152 KB Output is correct
22 Correct 4 ms 1152 KB Output is correct
23 Correct 5 ms 1152 KB Output is correct
24 Correct 5 ms 1152 KB Output is correct
25 Correct 9 ms 1212 KB Output is correct
26 Correct 10 ms 1152 KB Output is correct
27 Correct 10 ms 1152 KB Output is correct
28 Correct 6 ms 1152 KB Output is correct
29 Correct 4 ms 1152 KB Output is correct
30 Correct 10 ms 1152 KB Output is correct
31 Correct 4 ms 1152 KB Output is correct
32 Correct 4 ms 1176 KB Output is correct
33 Correct 137 ms 1324 KB Output is correct
34 Execution timed out 1068 ms 1368 KB Time limit exceeded
35 Halted 0 ms 0 KB -