Submission #137487

#TimeUsernameProblemLanguageResultExecution timeMemory
137487dndhkAsceticism (JOI18_asceticism)C++14
100 / 100
81 ms1272 KiB
#include <bits/stdc++.h>

#define pb push_back
#define all(v) ((v).begin(), (v).end())
#define sortv(v) sort(all(v))
#define sz(v) ((int)(v).size())
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define umax(a, b) (a)=max((a), (b))
#define umin(a, b) (a)=min((a), (b))
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,n) FOR(i,1,n)
#define rep0(i,n) FOR(i,0,(int)(n)-1)
#define FI first
#define SE second
#define INF 2000000000
#define INFLL 1000000000000000000LL


using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll DIV = 1000000007;

const int MAX_N = 100000;
int N, K;

ll ans;
ll pac[MAX_N+10];

ll multi(ll x, ll y){
	if(y==0)	return 1;
	if(y==1)	return x%DIV;
	ll m = multi(x, y/2);
	if(y%2){
		return m*m%DIV*x%DIV;
	}
	return m*m%DIV;
}

ll inv(ll x){
	return multi(x, DIV-2);
}

int main(){
	pac[0] = 1;
	for(ll i=1; i<MAX_N+10; i++){
		pac[i] = (pac[i-1] * i)%DIV;
	}
	scanf("%d%d", &N, &K);
	K--;
	ll t = 1;
	for(int i=0; i<=K; i++){
		ll add = (t * ((pac[N+1] * inv(pac[N-i+1])%DIV) * inv(pac[i])%DIV * multi(K+1-i, N))) % DIV;
		add = (add + DIV)%DIV;
		ans = (ans + add) % DIV;
		t = -t;
	}
	cout<<ans;
	return 0;
}

Compilation message (stderr)

asceticism.cpp: In function 'int main()':
asceticism.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &K);
  ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...