結果

問題 No.2221 Set X
ユーザー shobonvipshobonvip
提出日時 2023-02-17 22:40:06
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,400 bytes
コンパイル時間 4,331 ms
コンパイル使用メモリ 277,564 KB
実行使用メモリ 189,652 KB
最終ジャッジ日時 2023-09-26 19:59:16
合計ジャッジ時間 12,656 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
8,756 KB
testcase_01 AC 30 ms
4,376 KB
testcase_02 AC 30 ms
4,380 KB
testcase_03 AC 30 ms
4,380 KB
testcase_04 AC 30 ms
4,380 KB
testcase_05 AC 30 ms
4,380 KB
testcase_06 AC 30 ms
4,376 KB
testcase_07 AC 30 ms
4,384 KB
testcase_08 AC 31 ms
4,376 KB
testcase_09 AC 30 ms
4,376 KB
testcase_10 AC 33 ms
4,380 KB
testcase_11 AC 31 ms
4,380 KB
testcase_12 AC 31 ms
4,376 KB
testcase_13 AC 31 ms
4,384 KB
testcase_14 AC 34 ms
4,380 KB
testcase_15 AC 32 ms
4,376 KB
testcase_16 AC 936 ms
56,656 KB
testcase_17 AC 263 ms
17,676 KB
testcase_18 AC 1,135 ms
67,392 KB
testcase_19 AC 216 ms
15,544 KB
testcase_20 AC 542 ms
34,400 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 #

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

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

typedef long long ll;

vector<int> r[10000000];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);


	int n; cin >> n;
	set<int> xl;
	unordered_map<int,int> sashi;
	unordered_map<int,int> ars;
	int cnt = 0;
	int x = 0;
	vector<int> a(n);
	vector<int> b(n);
	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()){
				sashi[x] = cnt;
				r[cnt].push_back(i);
				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()){
					sashi[targ] = cnt;
					r[cnt].push_back(j);
					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