結果
| 問題 | No.3758 Fan Meeting |
| コンテスト | |
| ユーザー |
zawakasu
|
| 提出日時 | 2026-10-09 21:34:53 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 36 ms / 2,000 ms |
| + 182µs | |
| コード長 | 4,188 bytes |
| 記録 | |
| コンパイル時間 | 1,309 ms |
| コンパイル使用メモリ | 227,156 KB |
| 実行使用メモリ | 9,920 KB |
| 最終ジャッジ日時 | 2026-10-09 21:35:02 |
| 合計ジャッジ時間 | 4,849 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 47 |
ソースコード
#include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <tuple>
#include <ranges>
#include <random>
// #include "Src/Number/IntegerDivision.hpp"
#include <cstdint>
#include <cstddef>
namespace zawa {
using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using i128 = __int128_t;
using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using usize = std::size_t;
} // namespace zawa
#include <cmath>
#include <functional>
#include <type_traits>
namespace zawa {
namespace internal {
template <class T>
T MidPoint(T a, T b) {
if (a > b) std::swap(a, b);
return a + ((b - a) >> 1);
}
template <class T>
T Abs(T a, T b) {
return (a >= b ? a - b : b - a);
}
} // namespace zawa::internal
template <class T, class Function>
T BinarySearch(T ok, T ng, const Function& f) {
static_assert(std::is_integral_v<T>, "T must be integral type");
static_assert(std::is_convertible_v<Function, std::function<bool(T)>>, "f must be function bool(T)");
while (internal::Abs(ok, ng) > 1) {
T mid{ internal::MidPoint(ok, ng) };
(f(mid) ? ok : ng) = mid;
}
return ok;
}
template <class T, class Function>
T BinarySearch(T ok, T ng, const Function& f, u32 upperLimit) {
static_assert(std::is_signed_v<T>, "T must be signed arithmetic type");
static_assert(std::is_convertible_v<Function, std::function<bool(T)>>, "f must be function bool(T)");
for (u32 _{} ; _ < upperLimit ; _++) {
T mid{ (ok + ng) / (T)2 };
(f(mid) ? ok : ng) = mid;
}
return ok;
}
} // namespace zawa
// #include "Src/Sequence/CompressedSequence.hpp"
// #include "Src/Sequence/RunLengthEncoding.hpp"
// #include "Src/Algebra/Group/AdditiveGroup.hpp"
// #include "Src/DataStructure/FenwickTree/FenwickTree.hpp"
// #include "Src/DataStructure/SegmentTree/SegmentTree.hpp"
// #include "Src/DataStructure/DisjointSetUnion/DisjointSetUnion.hpp"
// #include "Src/DataStructure/Heap/BinaryHeap.hpp"
namespace zawa {}
using namespace zawa;
// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
// #include <array>
// #include <bit>
// #include <bitset>
// #include <climits>
// #include <cmath>
// #include <set>
// #include <unordered_set>
// #include <map>
// #include <unordered_map>
// #include <optional>
// #include <queue>
// #include <stack>
// #include <deque>
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
os << '(' << p.first << ',' << p.second << ')';
return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
for (int i = 0 ; i < ssize(v) ; i++)
os << v[i] << (i + 1 == ssize(v) ? "" : " ");
return os;
}
/*
* 二分探索f(t)
* 全員がt以下 -> S/Nの分身をA[i]時間交流させる
* そうじゃないとき -> max(A)+epsilonの分身でt人交流 -> 次の....となる
* それはできるんじゃない?
*/
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
#if !defined DEBUG
int N;
long long S;
cin >> N >> S;
vector<long long> A(N);
for (auto& x : A)
cin >> x;
ranges::sort(A,greater<>{});
auto f = [&](long long t) -> bool {
long long need=0;
for (long long i = 0 ; i < N ; ) {
if (A[i] > t) {
need += A[i];
i += t;
}
else
return need < S;
}
return need < S;
};
cout << BinarySearch((long long)1e9+10,0LL,f) << '\n';
#else
mt19937_64 mt{random_device{}()};
for (int testcase = 0 ; ; ) {
cerr << "----------" << ++testcase << "----------" << endl;
auto a = solve(), b = naive();
if (a != b) {
// print testcase
cerr << "you: " << a << endl;
cout << "correct: " << b << endl;
exit(0);
}
}
#endif
}
zawakasu