이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
const ll maxn = 1e6 + 1, maxm = 3e5 + 1;
const ll mod = 1e9 + 7, cmod = 998244353, inf = 1e9, blck = 400, p2 = 31;
const ld eps = 1e-9;
int n, a[maxn], cnt[maxn];;
ll fact[maxn];
int subtask1 = 0;
ll bp(ll a, ll n){
ll res = 1;
while (n > 0){
if (n & 1){
res *= a;
}
a *= a, n >>= 1;
a %= mod, res %= mod;
}
return res;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
fact[0] = 1;
set<int> setik;
for (int i = 1; i <= n; ++i){
cin >> a[i];
cnt[a[i]] += 1;
fact[i] = fact[i - 1] * i % mod;
setik.insert(a[i]);
}
if (setik.size() == 2){
subtask1 = 1;
}
if (subtask1 > 0){
int x = *setik.begin();
int y = *setik.rbegin();
ll ans = 0;
if (cnt[y] >= 2){
cnt[y] -= 2;
if (cnt[x] >= 2){
ll kol = fact[n - 2] * bp(fact[cnt[y]], mod - 2) % mod * bp(fact[cnt[x]], mod - 2) % mod;
kol -= (n - 2 - cnt[x] + 1);
ans += kol;
}
}
cout << ans;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |