結果
| 問題 |
No.1470 Mex Sum
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2021-04-09 21:29:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 45 ms / 2,000 ms |
| コード長 | 1,202 bytes |
| コンパイル時間 | 1,156 ms |
| コンパイル使用メモリ | 98,528 KB |
| 最終ジャッジ日時 | 2025-01-20 13:36:20 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 49 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
ll tri(ll n){
return (n*(n-1))/2;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
int n; cin >> n;
vector<ll> a(n);
for(int i = 0; i < n; i++) cin >> a[i];
map<ll, ll> cnt;
for(int x: a){
if(cnt.count(x) == 0) cnt[x] = 1;
else cnt[x]++;
}
ll m = n;
ll ans = 0;
if(cnt.count(1)){
m -= cnt[1];
ans += tri(cnt[1])*2;
ll k = m;
if(cnt.count(2)){
ans += cnt[1]*cnt[2]*3;
k -= cnt[2];
}
ans += cnt[1]*k*2;
}
ans += tri(m);
cout << ans << endl;
}
milanis48663220