結果
問題 | No.2221 Set X |
ユーザー |
![]() |
提出日時 | 2023-02-17 22:34:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,320 bytes |
コンパイル時間 | 4,280 ms |
コンパイル使用メモリ | 263,592 KB |
最終ジャッジ日時 | 2025-02-10 17:28:28 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 TLE * 22 |
ソースコード
#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; }