QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#103308 | #6130. Plants vs. Zombies | evirir# | RE | 2ms | 3376kb | C++20 | 2.2kb | 2023-05-05 07:09:20 | 2023-05-05 07:09:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define forn(i,a,b) for(int i = a; i < (b); i++)
#define fore(i,a,b) for(int i = a; i <= (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
void water_ij_until_i_near_target(ull target, const vector<ull> &a, vector<ull> &d, size_t i, size_t j, int &m) {
if (d[i] >= target) return;
ull waters = (target - d[i] - 1) / a[i];
if (waters == 0) return;
// cout << "watered " << i << " and " << j << ", took " << (waters * 2) << " waters" << endl;
d[i] += waters * a[i];
d[j] += waters * a[j];
m -= 2 * waters;
}
bool canReach(ull target, const vector<ull> &a, int n, int m) {
// cout << "target: " << target << endl;
vector<ull> d = a;
m -= n;
forn(i, 0, n - 1) {
water_ij_until_i_near_target(target, a, d, i, i+1, m);
if (m < 0) return false;
}
water_ij_until_i_near_target(target, a, d, n - 1, n - 2, m);
int cur_run = 0;
forn(i, 0, n) {
if (d[i] < target) {
cur_run++;
} else if (cur_run) {
int waters = 0;
if (i == n - 1) {
waters = cur_run;
} else {
waters = (cur_run + 1) / 2 * 2;
}
m -= waters;
// cout << "run from " << (i - cur_run) << " to " << (i - 1) << " took " << waters << endl;
cur_run = 0;
}
}
if (cur_run != 0) {
m -= (cur_run + 1) / 2 * 2;
}
return m >= 0;
}
void solve()
{
int n, m;
cin >> n >> m;
if (m < n) {
cout << 0 << endl;
return;
}
vector<ull> a(n, 0);
forn(i,0,n) cin >> a[i];
ull left = 0;
ull right = (*max_element(all(a)) + n - 1) / n * m;
while (left < right) {
ull mid = left + (right - left + 1) / 2;
if (canReach(mid, a, n, m)) {
left = mid;
} else {
right = mid - 1;
}
}
cout << right << endl;
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
int t; cin>>t;
forn(i,0,t) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3376kb
input:
2 4 8 3 2 6 6 3 9 10 10 1
output:
6 4
result:
ok 2 number(s): "6 4"
Test #2:
score: -100
Dangerous Syscalls
input:
116 4 0 3 2 6 6 4 1 3 2 6 6 10 19 10 2 8 4 2 4 9 3 3 3 4 8 3 9 3 6 2 19 2 10 11 15 3 1 1 4 3 7 10 8 6 7 10 10 14 8 7 1 1 10 9 2 8 10 7 2 13 2 3 10 10 8 1 6 6 9 4 7 1 8 8 7 14 6 7 4 5 3 1 3 11 6 8 1 10 9 7 2 6 6 1 3 9 4 10 6 1 3 8 7 7 10 6 2 10 4 7 2 5 11 9 10 5 9 2 9 1 2 4 8 6 2 8 8 1 6 4 5 7 2 9 8 ...
output:
0 0 1 4 6 20 3 2 14 1 4 0 0 0 0 1