QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#843824 | #9967. Imbalanced Teams | ucup-team3608# | WA | 0ms | 3632kb | C++20 | 3.4kb | 2025-01-05 03:01:31 | 2025-01-05 03:01:31 |
Judging History
answer
#include"bits/stdc++.h"
using namespace std;
using ll = long long;
/**
* Author: Chris
* Description: Find $x$ such that $ax \equiv 1$(mod $m$). The inverse
* only exist if $a$ and $m$ are coprimes.
*/
template<typename T> T minv(T a, T m) {
a %= m; assert(a);
return a == 1 ? 1 : T(m - ll(minv(m, a)) * m / a);
}
/**
* Author: Chris
* Date: 2021
* License: CC0
* Source: Yui Hosaka
* Description: Operators for modular arithmetic.
* Time:
* Status: extensively used.
*/
template<unsigned M_> struct modnum {
static constexpr unsigned M = M_; using num = modnum;
using ll = long long; using ull = unsigned long long; unsigned x;
num& norm(unsigned a){x = a<M ? a:a-M;return *this;}
constexpr modnum() : x(0U) {}
constexpr modnum(unsigned a) : x(a % M) {}
constexpr modnum(ull a) : x(a % M) {}
constexpr modnum(int a) : x(((a %= int(M))<0) ? (a+int(M)):a) {}
constexpr modnum(ll a) : x(((a %= ll(M))<0) ? (a+ll(M)):a) {}
explicit operator int() const { return x; }
num& operator+=(const num& a){ return norm(x+a.x); }
num& operator-=(const num& a){ return norm(x-a.x+M); }
num& operator*=(const num& a){ return norm(unsigned((ull(x)*a.x) % M)); }
num& operator/=(const num& a){ return (*this *= a.inv());}
template<typename T> friend num operator+(T a, const num& b){ return (num(a) += b); }
template<typename T> friend num operator-(T a, const num& b){ return (num(a) -= b); }
template<typename T> friend num operator*(T a, const num& b){ return (num(a) *= b); }
template<typename T> friend num operator/(T a, const num& b){ return (num(a) /= b); }
num operator+() const { return *this; }
num operator-() const { return num() - *this; }
num pow(ll e) const {
if (e < 0) { return inv().pow(-e); } num b = x, xe = 1U;
for (; e; e >>= 1) { if (e & 1) xe *= b; b *= b; }
return xe;
}
num inv() const { return minv(x, M); }
friend num inv(const num& a) { return a.inv(); }
explicit operator bool() const { return x; }
friend bool operator==(const num& a, const num& b){return a.x == b.x;}
friend bool operator!=(const num& a, const num& b){return a.x != b.x;}
};
using num = modnum<1000000007>;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
int n, k;
cin>>n>>k;
vector<int> v(n);
map<int, int> cnt;
for(auto &x: v){
cin>>x;
cnt[x]++;
}
sort(v.begin(), v.end());
vector<num> fact(n+1), ifact(n+1);
fact[0] = ifact[0] = 1;
for(int i = 1; i <=n; i++){
fact[i] = fact[i-1] * i;
ifact[i] = 1;
ifact[i] /= fact[i];
}
int last1 = v[k-1], cnt1 = 0;
int last2 = v[n - k], cnt2 = 0;
for(int i = k-1; i >=0; i--){
if(v[i] == last1) cnt1++;
}
for(int i = n-k; i <n; i++){
if(v[i] == last2) cnt2++;
}
auto nchoosek = [&](int n, int k) -> num{
num ans = fact[n];
ans *= ifact[k];
ans *= ifact[n-k];
return ans;
};
// cout<<last1<<" "<<cnt1<<"\t";
// cout<<last2<<" "<<cnt2<<"\t";
if(last1 == last2){
num ans = nchoosek(cnt[last1], cnt1) * nchoosek(cnt[last1]-cnt1, cnt2);
if(v[0] == v.back())
ans /= 2;
cout<<ans.x<<"\n";
} else {
num ans = nchoosek(cnt[last1], cnt1) * nchoosek(cnt[last2], cnt2);
cout<<ans.x<<"\n";
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3632kb
input:
6 2 2 5 7 2 5 2
output:
6
result:
wrong answer 1st numbers differ - expected: '8', found: '6'