Submission #23599283
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define endl "\n"
#define rep(i, n) for (int i = 0; i < n; i++)
//#define sort(v) sort(v.begin(), v.end());
//#define rsort(v) sort(v.rbegin(), v.rend());
void solve()
{
ll n;
cin >> n;
vector<ll> v(n);
map<ll, ll> m;
rep(i, n)
{
cin >> v[i];
m[v[i]]++;
}
ll sum = n;
ll res = 0;
for (int i = 0; i < n; i++)
{
res += sum - m[v[i]] - i;
if (m[v[i]] == 1)
{
m[v[i]]--;
//res++;
}
else if (m[v[i]] > 1)
{
m[v[i]]--;
}
}
cout << res << endl;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.in", "w", stdout);
#endif
int t;
t = 1;
while (t--)
{
solve();
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Swappable |
| User | EramallaAravind |
| Language | C++ (GCC 9.2.1) |
| Score | 300 |
| Code Size | 935 Byte |
| Status | AC |
| Exec Time | 309 ms |
| Memory | 24188 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | sample_01.txt, sample_02.txt, sample_03.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| sample_01.txt | AC | 5 ms | 3596 KiB |
| sample_02.txt | AC | 2 ms | 3596 KiB |
| sample_03.txt | AC | 2 ms | 3544 KiB |
| test_00.txt | AC | 2 ms | 3632 KiB |
| test_01.txt | AC | 2 ms | 3492 KiB |
| test_02.txt | AC | 38 ms | 3724 KiB |
| test_03.txt | AC | 194 ms | 12448 KiB |
| test_04.txt | AC | 70 ms | 4988 KiB |
| test_05.txt | AC | 43 ms | 3952 KiB |
| test_06.txt | AC | 36 ms | 3792 KiB |
| test_07.txt | AC | 309 ms | 24188 KiB |
| test_08.txt | AC | 96 ms | 5448 KiB |
| test_09.txt | AC | 95 ms | 5424 KiB |
| test_10.txt | AC | 156 ms | 5548 KiB |