結果
問題 | No.2221 Set X |
ユーザー |
![]() |
提出日時 | 2023-02-17 22:26:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,427 bytes |
コンパイル時間 | 4,847 ms |
コンパイル使用メモリ | 264,600 KB |
最終ジャッジ日時 | 2025-02-10 17:17:18 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; map<int,int> sashi; int cnt = 0; int x = 0; vector<int> a(n); vector<int> b(n); 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; //return 0; while (!xl.empty()){ auto xind = xl.end(); xind--; //cout << *xind << endl; 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; //cout << a[j] << endl; 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 << setnum * (x + 1) << " " << x << endl; } cout << ansx << endl; cout << ans << endl; }