Submission #43967

# Submission time Handle Problem Language Result Execution time Memory
43967 2018-03-29T01:18:01 Z model_code Asceticism (JOI18_asceticism) C++17
100 / 100
27 ms 3196 KB
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long long finv[110000];
long long inv[110000];
long long fact[110000];
long long C(int a,int b){
	if(a<b)return 0;
	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
long long f(int a,int b){
	long long ret=0;
	for(int i=0;i<=b;i++){
		long long t=pw(b-i,a)*finv[a]%mod*C(a,i)%mod;
		if(i%2)ret=(ret+mod-t)%mod;
		else ret=(ret+t)%mod;
	}
	return ret;
}
long long calc(int a,int b){
	long long ret=f(a,b+1);
	ret=(ret+mod-f(a,b))%mod;
	return ret;
}
int main(){
	fact[0]=1;
	for(int i=1;i<110000;i++)fact[i]=fact[i-1]*i%mod;
	inv[1]=1;
	for(int i=2;i<110000;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	finv[0]=1;
	for(int i=1;i<110000;i++){
		finv[i]=finv[i-1]*inv[i]%mod;
	}
	int N,K;scanf("%d%d",&N,&K);
	K--;
	printf("%lld\n",calc(N,K)*fact[N]%mod);
	
}

Compilation message

asceticism.cpp: In function 'int main()':
asceticism.cpp:62:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int N,K;scanf("%d%d",&N,&K);
          ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2904 KB Output is correct
2 Correct 8 ms 3052 KB Output is correct
3 Correct 8 ms 3064 KB Output is correct
4 Correct 8 ms 3064 KB Output is correct
5 Correct 8 ms 3064 KB Output is correct
6 Correct 8 ms 3064 KB Output is correct
7 Correct 9 ms 3064 KB Output is correct
8 Correct 9 ms 3064 KB Output is correct
9 Correct 8 ms 3064 KB Output is correct
10 Correct 8 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2904 KB Output is correct
2 Correct 8 ms 3052 KB Output is correct
3 Correct 8 ms 3064 KB Output is correct
4 Correct 8 ms 3064 KB Output is correct
5 Correct 8 ms 3064 KB Output is correct
6 Correct 8 ms 3064 KB Output is correct
7 Correct 9 ms 3064 KB Output is correct
8 Correct 9 ms 3064 KB Output is correct
9 Correct 8 ms 3064 KB Output is correct
10 Correct 8 ms 3064 KB Output is correct
11 Correct 8 ms 3064 KB Output is correct
12 Correct 8 ms 3064 KB Output is correct
13 Correct 8 ms 3080 KB Output is correct
14 Correct 8 ms 3080 KB Output is correct
15 Correct 8 ms 3080 KB Output is correct
16 Correct 8 ms 3080 KB Output is correct
17 Correct 8 ms 3124 KB Output is correct
18 Correct 9 ms 3124 KB Output is correct
19 Correct 8 ms 3136 KB Output is correct
20 Correct 8 ms 3156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2904 KB Output is correct
2 Correct 8 ms 3052 KB Output is correct
3 Correct 8 ms 3064 KB Output is correct
4 Correct 8 ms 3064 KB Output is correct
5 Correct 8 ms 3064 KB Output is correct
6 Correct 8 ms 3064 KB Output is correct
7 Correct 9 ms 3064 KB Output is correct
8 Correct 9 ms 3064 KB Output is correct
9 Correct 8 ms 3064 KB Output is correct
10 Correct 8 ms 3064 KB Output is correct
11 Correct 8 ms 3064 KB Output is correct
12 Correct 8 ms 3064 KB Output is correct
13 Correct 8 ms 3080 KB Output is correct
14 Correct 8 ms 3080 KB Output is correct
15 Correct 8 ms 3080 KB Output is correct
16 Correct 8 ms 3080 KB Output is correct
17 Correct 8 ms 3124 KB Output is correct
18 Correct 9 ms 3124 KB Output is correct
19 Correct 8 ms 3136 KB Output is correct
20 Correct 8 ms 3156 KB Output is correct
21 Correct 9 ms 3156 KB Output is correct
22 Correct 8 ms 3156 KB Output is correct
23 Correct 9 ms 3156 KB Output is correct
24 Correct 8 ms 3180 KB Output is correct
25 Correct 8 ms 3180 KB Output is correct
26 Correct 8 ms 3180 KB Output is correct
27 Correct 8 ms 3180 KB Output is correct
28 Correct 8 ms 3180 KB Output is correct
29 Correct 10 ms 3180 KB Output is correct
30 Correct 8 ms 3180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2904 KB Output is correct
2 Correct 8 ms 3052 KB Output is correct
3 Correct 8 ms 3064 KB Output is correct
4 Correct 8 ms 3064 KB Output is correct
5 Correct 8 ms 3064 KB Output is correct
6 Correct 8 ms 3064 KB Output is correct
7 Correct 9 ms 3064 KB Output is correct
8 Correct 9 ms 3064 KB Output is correct
9 Correct 8 ms 3064 KB Output is correct
10 Correct 8 ms 3064 KB Output is correct
11 Correct 8 ms 3064 KB Output is correct
12 Correct 8 ms 3064 KB Output is correct
13 Correct 8 ms 3080 KB Output is correct
14 Correct 8 ms 3080 KB Output is correct
15 Correct 8 ms 3080 KB Output is correct
16 Correct 8 ms 3080 KB Output is correct
17 Correct 8 ms 3124 KB Output is correct
18 Correct 9 ms 3124 KB Output is correct
19 Correct 8 ms 3136 KB Output is correct
20 Correct 8 ms 3156 KB Output is correct
21 Correct 9 ms 3156 KB Output is correct
22 Correct 8 ms 3156 KB Output is correct
23 Correct 9 ms 3156 KB Output is correct
24 Correct 8 ms 3180 KB Output is correct
25 Correct 8 ms 3180 KB Output is correct
26 Correct 8 ms 3180 KB Output is correct
27 Correct 8 ms 3180 KB Output is correct
28 Correct 8 ms 3180 KB Output is correct
29 Correct 10 ms 3180 KB Output is correct
30 Correct 8 ms 3180 KB Output is correct
31 Correct 9 ms 3180 KB Output is correct
32 Correct 9 ms 3196 KB Output is correct
33 Correct 9 ms 3196 KB Output is correct
34 Correct 13 ms 3196 KB Output is correct
35 Correct 23 ms 3196 KB Output is correct
36 Correct 25 ms 3196 KB Output is correct
37 Correct 27 ms 3196 KB Output is correct
38 Correct 10 ms 3196 KB Output is correct
39 Correct 14 ms 3196 KB Output is correct
40 Correct 16 ms 3196 KB Output is correct