跳到正文

个人记录

T1

_DaCapo_约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年5月3日
更新
2026年5月3日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[500005];
int zero;
int one;
bool flag = false;
set<int>st;
int main() {
	cin >> n;
	for (int i = 1;i <= n;i++) {
		cin >> a[i];
		if (a[i] == 0)zero++;
		if (a[i] == 1)one++;
		if (a[i] >= 2)flag = true;
	}
	if (zero == 0) {
		cout << "0" << endl;
		return 0;
	}
	if (flag == false) {
		if (one == 1) {
			cout << "1" << endl;
		}
		else if (one == 0) {
			cout << "0" << endl;
		}
		else cout << "2" << endl;
	}
	else {
		sort(a + 1, a + 1 + n);
		long long l = a[n];
		a[n] = 0;
		for (int i = 1;i <= n;i++) {
			st.insert(a[i]);
		}
		long long r = 0;
		auto it = st.find(r);
		while (it != st.end()) {
			r++;
			it = st.find(r);
		}
		cout << r * l;
	}
	return 0;
}
原文