結果

問題 No.2221 Set X
ユーザー shobonvipshobonvip
提出日時 2023-02-17 22:34:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,320 bytes
コンパイル時間 4,578 ms
コンパイル使用メモリ 273,276 KB
実行使用メモリ 177,436 KB
最終ジャッジ日時 2023-09-26 19:52:21
合計ジャッジ時間 11,825 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,768 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 939 ms
56,540 KB
testcase_17 AC 247 ms
17,572 KB
testcase_18 AC 1,154 ms
67,680 KB
testcase_19 AC 198 ms
15,536 KB
testcase_20 AC 542 ms
34,456 KB
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;

typedef modint998244353 mint;
typedef long long ll;

int main(){
	int n; cin >> n;
	set<int> xl;
	vector<vector<int>> r;
	unordered_map<int,int> sashi;
	int cnt = 0;
	int x = 0;
	vector<int> a(n);
	vector<int> b(n);
	unordered_map<int,int> ars;
	int am = 0;

	ll setnum = 0;
	for (int i=0; i<n; i++){
		int x; cin >> x;
		b[i] = x;

		if (ars[0] == 0) setnum++;
		ars[0]++;

		am = max(am, x);

		if (x > 0){
			if (xl.find(x) == xl.end()){
				r.push_back({i});
				sashi[x] = cnt;
				cnt++;
				xl.insert(x);
			}else{
				r[sashi[x]].push_back(i);
			}
		}
	}

	ll ans = (ll)am + 2;
	int ansx = am + 1;

	while (!xl.empty()){
		auto xind = xl.end();
		xind--;

		int x = *xind;
		xl.erase(xind);

		for (int j: r[sashi[x]]){
			ars[a[j]]--;
			if (ars[a[j]] == 0){
				setnum--;
			}

			a[j] = b[j] / x;

			if (ars[a[j]] == 0){
				setnum++;
			}
			ars[a[j]]++;

			int targ = b[j] / (a[j] + 1);
			if (targ > 0){
				if (xl.find(targ) == xl.end()){
					r.push_back({j});
					sashi[targ] = cnt;
					cnt++;
					xl.insert(targ);
				}else{
					r[sashi[targ]].push_back(j);
				}
			}
		}

		if (ans >= setnum * (x + 1)){
			ans = setnum * (x + 1);
			ansx = x;
		}

	}

	cout << ansx << endl;
	cout << ans << endl;
}
0