結果
| 問題 | No.2221 Set X |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-02 04:01:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,704 bytes |
| 記録 | |
| コンパイル時間 | 2,222 ms |
| コンパイル使用メモリ | 206,228 KB |
| 実行使用メモリ | 143,708 KB |
| 最終ジャッジ日時 | 2025-12-02 04:01:29 |
| 合計ジャッジ時間 | 6,495 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 3 WA * 10 TLE * 1 -- * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
if (!(cin >> N)) return 0;
vector<long long> A(N);
for (int i = 0; i < N; ++i) cin >> A[i];
long long maxA = A.back();
// Collect candidate widths
vector<long long> cand;
// Always reasonable to try small widths directly
long long LIM = 100000; // can be tuned; N up to 1e5, A[i] up to 1e9
for (long long w = 1; w * w <= maxA; ++w) cand.push_back(w);
// For each A[i], add floor divisions that can appear as optimal W
for (int i = 0; i < N; ++i) {
long long x = A[i];
if (x == 0) continue;
long long t = sqrtl((long double)x);
for (long long k = 1; k <= t; ++k) {
long long w = x / k; // floor(x / k)
if (w >= 1) cand.push_back(w);
if (w - 1 >= 1) cand.push_back(w - 1);
}
}
sort(cand.begin(), cand.end());
cand.erase(unique(cand.begin(), cand.end()), cand.end());
auto cost = [&](long long W) -> long long {
long long prev = -1, cnt = 0;
for (int i = 0; i < N; ++i) {
long long s = A[i] / W;
if (s != prev) {
++cnt;
prev = s;
}
}
return cnt * (W + 1);
};
long long bestW = 1;
long long bestCost = cost(1);
for (long long W : cand) {
if (W <= 0) continue;
long long c = cost(W);
if (c < bestCost || (c == bestCost && W < bestW)) {
bestCost = c;
bestW = W;
}
}
cout << bestW << "\n" << bestCost << "\n";
return 0;
}