結果

問題 No.1470 Mex Sum
ユーザー takumattakumat
提出日時 2021-04-09 22:04:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,206 bytes
コンパイル時間 4,573 ms
コンパイル使用メモリ 262,732 KB
実行使用メモリ 4,916 KB
最終ジャッジ日時 2023-09-07 11:23:15
合計ジャッジ時間 8,411 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 6 ms
4,380 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 6 ms
4,376 KB
testcase_05 AC 6 ms
4,380 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 47 ms
4,756 KB
testcase_13 AC 47 ms
4,776 KB
testcase_14 AC 46 ms
4,700 KB
testcase_15 AC 48 ms
4,696 KB
testcase_16 AC 45 ms
4,692 KB
testcase_17 AC 45 ms
4,704 KB
testcase_18 AC 46 ms
4,716 KB
testcase_19 AC 45 ms
4,580 KB
testcase_20 AC 45 ms
4,780 KB
testcase_21 AC 47 ms
4,768 KB
testcase_22 AC 48 ms
4,652 KB
testcase_23 AC 47 ms
4,604 KB
testcase_24 AC 47 ms
4,716 KB
testcase_25 AC 50 ms
4,664 KB
testcase_26 AC 48 ms
4,696 KB
testcase_27 AC 47 ms
4,764 KB
testcase_28 AC 48 ms
4,728 KB
testcase_29 AC 47 ms
4,656 KB
testcase_30 AC 47 ms
4,696 KB
testcase_31 AC 47 ms
4,588 KB
testcase_32 AC 48 ms
4,604 KB
testcase_33 AC 47 ms
4,608 KB
testcase_34 AC 47 ms
4,632 KB
testcase_35 AC 47 ms
4,696 KB
testcase_36 AC 47 ms
4,700 KB
testcase_37 AC 34 ms
4,764 KB
testcase_38 AC 33 ms
4,604 KB
testcase_39 AC 34 ms
4,916 KB
testcase_40 AC 35 ms
4,696 KB
testcase_41 AC 35 ms
4,584 KB
testcase_42 AC 35 ms
4,652 KB
testcase_43 AC 36 ms
4,756 KB
testcase_44 AC 35 ms
4,608 KB
testcase_45 AC 35 ms
4,656 KB
testcase_46 AC 35 ms
4,636 KB
testcase_47 AC 35 ms
4,580 KB
testcase_48 AC 35 ms
4,580 KB
testcase_49 AC 35 ms
4,672 KB
testcase_50 AC 35 ms
4,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007LL; //998244353LL;
static const LLONG INF_NUM = LLONG_MAX / 20LL;
template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void task();

int main()
{
	task();
	fflush(stdout);
	return 0;
}

static void task()
{
	int N;
	get(N);
	std::vector<LLONG> ai(N);
	for (int i = 0; i < N; i++) {
		get(ai[i]);
	}

	std::sort(ai.begin(), ai.end());

	int oneOver = N, twoOver = N;
	for (int i = 0; i < N; i++) {
		if (ai[i] > 1) {
			if(oneOver == N) oneOver = i;
		}
		if (ai[i] > 2) {
			if (twoOver == N) twoOver = i;
		}
	}

	LLONG ans = 0;
	for (int i = 0; i < N - 1; i++) {
		if (i < oneOver) {
			ans += 2LL * (LLONG)(oneOver - i - 1);
			ans += 3LL * (LLONG)(twoOver - oneOver);
			ans += 2LL * (LLONG)(N - twoOver);
		}
		else {
			ans += (LLONG)(N - i - 1);
		}
	}
	printf("%lld\n", ans);
}
0