답안 #536049

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
536049 2022-03-12T08:07:43 Z inksamurai Magneti (COCI21_magneti) C++17
10 / 110
1 ms 724 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,x,n) for(int i=x;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3HspL4A ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vec(int);
void print(){cout<<"\n";}
template<class T,class...E>
void print(const T&v,const E&...u){cout<<v<<' ',print(u...);}
// e

//snuke's mod int
template <ll mod>
struct modint{
	ll x; // typedef long long ll;
	modint(ll x=0):x((x%mod+mod)%mod){}
	modint operator-()const{return modint(-x);}
	modint& operator+=(const modint a){if((x+=a.x)>=mod) x-=mod; return *this;}
	modint& operator-=(const modint a){if((x+=mod-a.x)>=mod) x-=mod; return *this;}
	modint& operator*=(const modint a){(x*=a.x)%=mod; return *this;}
	modint operator+(const modint a)const{modint res(*this); return res+=a;}
	modint operator-(const modint a)const{modint res(*this); return res-=a;}
	modint operator*(const modint a)const{modint res(*this); return res*=a;}
	modint pow(ll n)const{
		modint res=1,x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	modint inv()const{return pow(mod-2);}
};
using mint=modint<1000'000'007>;

const int nax=20000;
mint fact[nax+10];
void pfact(){
fact[0]=fact[1]=1;
  rng(i,2,nax){
    mint x=i;
    fact[i]=fact[i-1]*x;
  }
}

mint cnk(ll k,ll n){
  if(k>n) return 0;
  mint e=fact[k]*fact[n-k];
  return fact[n]*e.inv();
}


signed main(){
_3HspL4A;
	pfact();
	int n,len;
	cin>>n>>len;
	vi a(n);
	rep(i,n){
		cin>>a[i];
	}
	rep(i,n){
		a[i]-=1;
	}
	assert(*min_element(a.begin(),a.end())==*max_element(a.begin(),a.end()));
	if(len-n>=a[0]*(n-1)){
		len-=n;
		len-=a[0]*(n-1);
		mint ans=cnk(n,len+n)*fact[n];
		print(ans.x);
		// v | .v . | .v . | .v . | v

	}else{
		print(0);
	}
//	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 480 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 724 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 724 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 480 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Runtime error 1 ms 724 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -