結果
| 問題 | No.2221 Set X |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-20 16:20:19 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,707 bytes |
| 記録 | |
| コンパイル時間 | 2,919 ms |
| コンパイル使用メモリ | 108,652 KB |
| 実行使用メモリ | 13,292 KB |
| 最終ジャッジ日時 | 2024-09-20 16:20:29 |
| 合計ジャッジ時間 | 9,729 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 TLE * 1 -- * 21 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
using ll = long long;
const ll N = 2 * 100000 + 10;
struct Segment {
ll q, L, R;
};
vector<Segment> floor_decomposition(ll x) {
vector<Segment> res;
ll R = 1e18;
while (R) {
ll q = x / R;
ll L = x / (q + 1);
res.push_back({q, L, R});
R = L;
}
return res;
}
vector<pair<ll, ll>> merge(const vector<Segment> &A, const vector<Segment> &B) {
int i = 0, j = 0;
vector<pair<ll, ll>> ans;
ll X = 1e18;
while (i < A.size() && j < B.size()) {
if (A[i].q < B[j].q) {
ans.push_back({max(A[i].L, B[j].L), X});
}
X = max(A[i].L, B[j].L);
if (A[i].L < B[j].L) {
j++;
} else {
i++;
}
}
return ans;
}
int main() {
ll n;
cin >> n;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<ll> rui(N + 1, 0);
auto pre = floor_decomposition(a[0]);
for (int i = 0; i < n - 1; i++) {
auto now = floor_decomposition(a[i + 1]);
for (auto &[l, r] : merge(pre, now)) {
if (r + 1 <= N) {
rui[r + 1]--;
}
if (l + 1 <= N) {
rui[l + 1]++;
}
}
pre = now;
}
for (int i = 0; i < N; i++) {
rui[i + 1] += rui[i];
}
ll ans = LLONG_MAX;
ll I = -1;
for (ll i = 1; i < N; i++) {
ll val = (1 + rui[i]) * (i + 1);
if (ans > val) {
ans = val;
I = i;
}
}
cout << I << endl;
cout << ans << endl;
return 0;
}