Submission #58898

# Submission time Handle Problem Language Result Execution time Memory
58898 2018-07-19T18:57:11 Z TadijaSebez Asceticism (JOI18_asceticism) C++11
100 / 100
19 ms 2476 KB
#include <stdio.h>
#define ll long long
const int N=200050;
const int mod=1000000007;
int F[N],I[N];
int pow(int x, int k){ int ret=1;for(;k;k>>=1,x=(ll)x*x%mod) if(k&1) ret=(ll)ret*x%mod;return ret;}
int get(int n, int k){ return (ll)F[n]*I[k]%mod*I[n-k]%mod;}
int calc(int n, int k)
{
	if(k>n) return 0;
	int ret=0;
	for(int i=0;i<=k;i++)
	{
		int add=(ll)get(n+1,i)*pow(k+1-i,n)%mod;
		if(i&1) ret=(ret-add+mod)%mod;
		else ret=(ret+add)%mod;
	}
	return ret;
}
int main()
{
	int n,k,x,i,sum=0;
	F[0]=1;for(i=1;i<N;i++) F[i]=(ll)F[i-1]*i%mod;
	I[N-1]=pow(F[N-1],mod-2);for(i=N-2;i>=0;i--) I[i]=(ll)I[i+1]*(i+1)%mod;
	scanf("%i %i",&n,&k);
	printf("%i\n",calc(n,k-1));
	return 0;
}

Compilation message

asceticism.cpp: In function 'int main()':
asceticism.cpp:22:10: warning: unused variable 'x' [-Wunused-variable]
  int n,k,x,i,sum=0;
          ^
asceticism.cpp:22:14: warning: unused variable 'sum' [-Wunused-variable]
  int n,k,x,i,sum=0;
              ^~~
asceticism.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&k);
  ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1912 KB Output is correct
2 Correct 7 ms 1912 KB Output is correct
3 Correct 7 ms 1972 KB Output is correct
4 Correct 7 ms 2088 KB Output is correct
5 Correct 6 ms 2088 KB Output is correct
6 Correct 9 ms 2140 KB Output is correct
7 Correct 6 ms 2148 KB Output is correct
8 Correct 8 ms 2148 KB Output is correct
9 Correct 8 ms 2264 KB Output is correct
10 Correct 7 ms 2264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1912 KB Output is correct
2 Correct 7 ms 1912 KB Output is correct
3 Correct 7 ms 1972 KB Output is correct
4 Correct 7 ms 2088 KB Output is correct
5 Correct 6 ms 2088 KB Output is correct
6 Correct 9 ms 2140 KB Output is correct
7 Correct 6 ms 2148 KB Output is correct
8 Correct 8 ms 2148 KB Output is correct
9 Correct 8 ms 2264 KB Output is correct
10 Correct 7 ms 2264 KB Output is correct
11 Correct 8 ms 2280 KB Output is correct
12 Correct 7 ms 2284 KB Output is correct
13 Correct 8 ms 2284 KB Output is correct
14 Correct 7 ms 2284 KB Output is correct
15 Correct 7 ms 2284 KB Output is correct
16 Correct 7 ms 2284 KB Output is correct
17 Correct 8 ms 2284 KB Output is correct
18 Correct 7 ms 2284 KB Output is correct
19 Correct 6 ms 2284 KB Output is correct
20 Correct 6 ms 2284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1912 KB Output is correct
2 Correct 7 ms 1912 KB Output is correct
3 Correct 7 ms 1972 KB Output is correct
4 Correct 7 ms 2088 KB Output is correct
5 Correct 6 ms 2088 KB Output is correct
6 Correct 9 ms 2140 KB Output is correct
7 Correct 6 ms 2148 KB Output is correct
8 Correct 8 ms 2148 KB Output is correct
9 Correct 8 ms 2264 KB Output is correct
10 Correct 7 ms 2264 KB Output is correct
11 Correct 8 ms 2280 KB Output is correct
12 Correct 7 ms 2284 KB Output is correct
13 Correct 8 ms 2284 KB Output is correct
14 Correct 7 ms 2284 KB Output is correct
15 Correct 7 ms 2284 KB Output is correct
16 Correct 7 ms 2284 KB Output is correct
17 Correct 8 ms 2284 KB Output is correct
18 Correct 7 ms 2284 KB Output is correct
19 Correct 6 ms 2284 KB Output is correct
20 Correct 6 ms 2284 KB Output is correct
21 Correct 8 ms 2284 KB Output is correct
22 Correct 8 ms 2284 KB Output is correct
23 Correct 8 ms 2284 KB Output is correct
24 Correct 7 ms 2284 KB Output is correct
25 Correct 8 ms 2300 KB Output is correct
26 Correct 7 ms 2300 KB Output is correct
27 Correct 7 ms 2300 KB Output is correct
28 Correct 7 ms 2300 KB Output is correct
29 Correct 7 ms 2320 KB Output is correct
30 Correct 8 ms 2320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1912 KB Output is correct
2 Correct 7 ms 1912 KB Output is correct
3 Correct 7 ms 1972 KB Output is correct
4 Correct 7 ms 2088 KB Output is correct
5 Correct 6 ms 2088 KB Output is correct
6 Correct 9 ms 2140 KB Output is correct
7 Correct 6 ms 2148 KB Output is correct
8 Correct 8 ms 2148 KB Output is correct
9 Correct 8 ms 2264 KB Output is correct
10 Correct 7 ms 2264 KB Output is correct
11 Correct 8 ms 2280 KB Output is correct
12 Correct 7 ms 2284 KB Output is correct
13 Correct 8 ms 2284 KB Output is correct
14 Correct 7 ms 2284 KB Output is correct
15 Correct 7 ms 2284 KB Output is correct
16 Correct 7 ms 2284 KB Output is correct
17 Correct 8 ms 2284 KB Output is correct
18 Correct 7 ms 2284 KB Output is correct
19 Correct 6 ms 2284 KB Output is correct
20 Correct 6 ms 2284 KB Output is correct
21 Correct 8 ms 2284 KB Output is correct
22 Correct 8 ms 2284 KB Output is correct
23 Correct 8 ms 2284 KB Output is correct
24 Correct 7 ms 2284 KB Output is correct
25 Correct 8 ms 2300 KB Output is correct
26 Correct 7 ms 2300 KB Output is correct
27 Correct 7 ms 2300 KB Output is correct
28 Correct 7 ms 2300 KB Output is correct
29 Correct 7 ms 2320 KB Output is correct
30 Correct 8 ms 2320 KB Output is correct
31 Correct 7 ms 2324 KB Output is correct
32 Correct 6 ms 2328 KB Output is correct
33 Correct 7 ms 2332 KB Output is correct
34 Correct 9 ms 2336 KB Output is correct
35 Correct 16 ms 2340 KB Output is correct
36 Correct 17 ms 2340 KB Output is correct
37 Correct 19 ms 2348 KB Output is correct
38 Correct 9 ms 2476 KB Output is correct
39 Correct 12 ms 2476 KB Output is correct
40 Correct 12 ms 2476 KB Output is correct