QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#657162 | #6130. Plants vs. Zombies | kazimiyuuka | WA | 0ms | 3556kb | C++20 | 1.6kb | 2024-10-19 14:16:58 | 2024-10-19 14:16:58 |
Judging History
answer
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <random>
#include <cstdlib>
#include <numeric>
#include <functional>
#include <queue>
using namespace std;
using ll = long long;
ll mod = 1e9 + 7;
void slove()
{
ll n, m;
cin >> n >> m;
vector<ll> data(n + 1);
vector<ll> tim(n + 2);
for (int i = 1; i <= n; i++) cin >> data[i];
ll mi = data[0];
for (int i = 1; i <= n; i++) {
if (data[i] == 0) {
cout << 0 << endl;
return;
}
mi = min(data[i], mi);
}
ll l = 0, r = (ll)mi * m;
function<ll(ll)> check = [&](ll low) {
if (low == 0) return 0LL;
for (int i = 1; i <= n; i++) tim[i] = (low + data[i] - 1) / data[i];
ll ned = 0;
for (int i = 1; i <= n; i++) {
// 第一次走过来
ned++;
tim[i]--;
// 如果小于0可以直接走到下一个点
if (tim[i] <= 0) continue;
ll tmp = min(tim[i], tim[i + 1]);
ned += tmp * 2LL;
tim[i] -= tmp;
tim[i + 1] -= tmp;
ned += tim[i] * 2LL;
// 如果最后一个数已经达标,不必要走
if (i + 1 == n && tim[i + 1] <= 0) break;
}
return ned;
};
while (l < r) {
ll mid = (l + r) / 2LL + 1LL;
if (check(mid) > m)
r = mid - 1;
else
l = mid;
}
cout << l << endl;
}
int main()
{
//freopen("out.txt", "w", stdout);
//freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int cnt = 1;
cin >> cnt;
while (cnt--)
{
slove();
}
};
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3556kb
input:
2 4 8 3 2 6 6 3 9 10 10 1
output:
0 0
result:
wrong answer 1st numbers differ - expected: '6', found: '0'