From f285b09aaeae655e2dd523189a6f724544b632e8 Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Sat, 17 Dec 2022 14:48:54 +0200 Subject: Solved A in Div2 #837 --- codeforces/HossamAndCombinatorics/main | Bin 0 -> 45416 bytes codeforces/HossamAndCombinatorics/main.cpp | 104 +++++++++++++++++++++ codeforces/HossamAndCombinatorics/main_input0.txt | 5 + codeforces/HossamAndCombinatorics/main_input1.txt | 3 + codeforces/HossamAndCombinatorics/main_input2.txt | 3 + codeforces/HossamAndCombinatorics/main_input3.txt | 3 + codeforces/HossamAndCombinatorics/main_input4.txt | 3 + codeforces/HossamAndCombinatorics/main_output0.txt | 2 + codeforces/HossamAndCombinatorics/main_output1.txt | 1 + codeforces/HossamAndCombinatorics/main_output2.txt | 1 + codeforces/HossamAndCombinatorics/main_output3.txt | 1 + codeforces/HossamAndCombinatorics/main_output4.txt | 1 + 12 files changed, 127 insertions(+) create mode 100755 codeforces/HossamAndCombinatorics/main create mode 100644 codeforces/HossamAndCombinatorics/main.cpp create mode 100644 codeforces/HossamAndCombinatorics/main_input0.txt create mode 100644 codeforces/HossamAndCombinatorics/main_input1.txt create mode 100644 codeforces/HossamAndCombinatorics/main_input2.txt create mode 100644 codeforces/HossamAndCombinatorics/main_input3.txt create mode 100644 codeforces/HossamAndCombinatorics/main_input4.txt create mode 100644 codeforces/HossamAndCombinatorics/main_output0.txt create mode 100644 codeforces/HossamAndCombinatorics/main_output1.txt create mode 100644 codeforces/HossamAndCombinatorics/main_output2.txt create mode 100644 codeforces/HossamAndCombinatorics/main_output3.txt create mode 100644 codeforces/HossamAndCombinatorics/main_output4.txt (limited to 'codeforces') diff --git a/codeforces/HossamAndCombinatorics/main b/codeforces/HossamAndCombinatorics/main new file mode 100755 index 0000000..0a80c3a Binary files /dev/null and b/codeforces/HossamAndCombinatorics/main differ diff --git a/codeforces/HossamAndCombinatorics/main.cpp b/codeforces/HossamAndCombinatorics/main.cpp new file mode 100644 index 0000000..c9d670e --- /dev/null +++ b/codeforces/HossamAndCombinatorics/main.cpp @@ -0,0 +1,104 @@ +#include +#include +using namespace std; + +using ll = long long; +using pi = pair; +using vpi = vector; +using vi = vector; +using vll = vector; +using mpii = map; +using mpll = map; +using db = long double; + +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define lb lower_bound +#define ub upper_bound + +const int MOD = (int)1e9 + 7; +const db PI = acos((db)-1); +const int dx[4]{1, 0, -1, 0}; +const int dy[4]{0, 1, 0, -1}; + +//pretty printing +template +void printm(const map &mp) { + cerr << "{" << endl; + for (auto p : mp) { + cerr << " { " << p.first << " : " << p.second << " }\n"; + } + cerr << "}" << endl; +} +template +void printv(const vector &v) { + cerr << "["; + for (int i = 0; i < v.size(); i++) { + if (i == v.size() - 1) { + cerr << v[i]; + } else { + cerr << v[i] << ", "; + } + } + cerr << "]\n"; +} + +template +void printvv(const vector> &v) { + cerr << "[\n"; + for (auto &vec : v) { + cout << " "; + printv(vec); + } + cerr << "]\n"; +} +void print() { + cerr << "\n"; +} + +template +void print(T val, TS... vals) { + cerr << val << " "; + print(vals...); +} + + +/* stuff you should look for: + --------------------------- + * special cases (n=1?) + * int overflow, array bounds + * do smth instead of nothing and stay organized + * WRITE STUFF DOWN + * DON'T GET STUCK ON ONE APPROACH + */ + +void solve() { + ll n; + cin >> n; + vll v(n), fq(1e5 + 5, 0); + for (int i = 0; i < n; i++) { + cin >> v[i]; + fq[v[i]]++; + } + sort(all(v)); + ll ans = 0; + if (v[0] == v[v.size() - 1]) { + ans = n * (n - 1); + } else { + ans = fq[v[0]] * fq[v[v.size() - 1]] * 2; + } + cout << ans << '\n'; +} + +int main () { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while(tt--) { + solve(); + } +} + + diff --git a/codeforces/HossamAndCombinatorics/main_input0.txt b/codeforces/HossamAndCombinatorics/main_input0.txt new file mode 100644 index 0000000..8ba6781 --- /dev/null +++ b/codeforces/HossamAndCombinatorics/main_input0.txt @@ -0,0 +1,5 @@ +2 +5 +6 2 3 8 1 +6 +7 2 8 3 2 10 diff --git a/codeforces/HossamAndCombinatorics/main_input1.txt b/codeforces/HossamAndCombinatorics/main_input1.txt new file mode 100644 index 0000000..2b72911 --- /dev/null +++ b/codeforces/HossamAndCombinatorics/main_input1.txt @@ -0,0 +1,3 @@ +1 +5 +2 2 2 10 10 \ No newline at end of file diff --git a/codeforces/HossamAndCombinatorics/main_input2.txt b/codeforces/HossamAndCombinatorics/main_input2.txt new file mode 100644 index 0000000..e64d056 --- /dev/null +++ b/codeforces/HossamAndCombinatorics/main_input2.txt @@ -0,0 +1,3 @@ +1 +9 +2 2 2 1 1 9 9 10 10 \ No newline at end of file diff --git a/codeforces/HossamAndCombinatorics/main_input3.txt b/codeforces/HossamAndCombinatorics/main_input3.txt new file mode 100644 index 0000000..7fd6ee5 --- /dev/null +++ b/codeforces/HossamAndCombinatorics/main_input3.txt @@ -0,0 +1,3 @@ +1 +10 +1 1 1 1 1 10 10 10 10 10 \ No newline at end of file diff --git a/codeforces/HossamAndCombinatorics/main_input4.txt b/codeforces/HossamAndCombinatorics/main_input4.txt new file mode 100644 index 0000000..b0a2002 --- /dev/null +++ b/codeforces/HossamAndCombinatorics/main_input4.txt @@ -0,0 +1,3 @@ +1 +5 +1 1 1 1 1 \ No newline at end of file diff --git a/codeforces/HossamAndCombinatorics/main_output0.txt b/codeforces/HossamAndCombinatorics/main_output0.txt new file mode 100644 index 0000000..da7f847 --- /dev/null +++ b/codeforces/HossamAndCombinatorics/main_output0.txt @@ -0,0 +1,2 @@ +2 +4 diff --git a/codeforces/HossamAndCombinatorics/main_output1.txt b/codeforces/HossamAndCombinatorics/main_output1.txt new file mode 100644 index 0000000..3cacc0b --- /dev/null +++ b/codeforces/HossamAndCombinatorics/main_output1.txt @@ -0,0 +1 @@ +12 \ No newline at end of file diff --git a/codeforces/HossamAndCombinatorics/main_output2.txt b/codeforces/HossamAndCombinatorics/main_output2.txt new file mode 100644 index 0000000..2edeafb --- /dev/null +++ b/codeforces/HossamAndCombinatorics/main_output2.txt @@ -0,0 +1 @@ +20 \ No newline at end of file diff --git a/codeforces/HossamAndCombinatorics/main_output3.txt b/codeforces/HossamAndCombinatorics/main_output3.txt new file mode 100644 index 0000000..c5b431b --- /dev/null +++ b/codeforces/HossamAndCombinatorics/main_output3.txt @@ -0,0 +1 @@ +50 \ No newline at end of file diff --git a/codeforces/HossamAndCombinatorics/main_output4.txt b/codeforces/HossamAndCombinatorics/main_output4.txt new file mode 100644 index 0000000..2edeafb --- /dev/null +++ b/codeforces/HossamAndCombinatorics/main_output4.txt @@ -0,0 +1 @@ +20 \ No newline at end of file -- cgit v1.2.3