結果

問題 No.1470 Mex Sum
ユーザー jj_george_
提出日時 2021-07-20 20:32:29
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 702 bytes
コンパイル時間 596 ms
コンパイル使用メモリ 72,180 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-17 13:48:00
合計ジャッジ時間 3,619 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

ll nC2(ll n) {
	if (n <= 1)
		return 0;
	return n * (n - 1) / 2;
}

int main(void) {
	ll i, num, a = 0, b = 0, x, ans = 0;
	cin >> num;
	rep(i, num) {
		cin >> x;
		if (x == 1)
			a++;
		else if (x == 2)
			b++;
	}
	ans += a * b * 3;
	ans += (nC2(a) + a * (num - a - b)) * 2;
	ans += nC2(num - a);
	cout << ans << "\n";
	return 0;
}
0