# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
700660 | | Nursik | W (RMI18_w) | C++14 | | 363 ms | 21796 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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... |