# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
973508 | FynjyBath | Hexagonal Territory (APIO21_hexagon) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt,tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define F first
#define S second
#define endl '\n'
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int rnd(int n) { uniform_int_distribution <int> uid(0, n - 1); return uid(rng); }
double rndd() { return double(rand()) / RAND_MAX; }
struct hash_pair {
template <class T1, class T2>
size_t operator()(const pair<T1, T2>& p) const {
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return (hash1 << 5) ^ hash2;
}
};
ll t, n, a, b, k;
ll ca, cb;
void solve() {
cin >> t >> n >> a >> b >> k;
ca = (n + 1) / 2, cb = n / 2;
if (ca + cb < k) {
cout << 0 << '\n';
return;
}
if (a < b) {
swap(a, b);
swap(ca, cb);
}
if (ca >= k) {
cout << min(t, (a * 1ll * ca + b * 1ll * cb) / k) << '\n';
return;
}
int l = -1, r = 1e9 + 10;
while (r - l > 1) {
int m = l + (r - l) / 2;
long long restA = a - m, restB = b - (m * 1ll * (k - ca) + cb - 1) / cb;
if (restA >= 0 && restB >= 0 && restA >= restB) {
l = m;
} else {
r = m;
}
}
long long restA = a - l, restB = b - (l * 1ll * (k - ca) + cb - 1) / cb;
cout << min(t * 1ll, l + restB * 1ll * (ca + cb)) << '\n';
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
auto start_time = chrono::high_resolution_clock::now();
int tt = 1;
//cin >> tt;
for (int _ = 0; _ < tt; _++)
solve();
cerr << "Ulyanovsk is the best" << endl;
auto end_time = chrono::high_resolution_clock::now();
cerr << "Execution time: " <<
chrono::duration_cast<chrono::milliseconds>(end_time - start_time).count() << " ms" << endl;
}