QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#497048 | #6134. Soldier Game | ucup-team1198# | WA | 1301ms | 4940kb | C++14 | 3.1kb | 2024-07-28 18:26:01 | 2024-07-28 18:26:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
vector<array<int, 2>> norm(const vector<array<int, 2>>& arr) {
vector<array<int, 2>> ans;
for (auto elem : arr) {
if (!ans.empty() && elem[1] >= ans.back()[1]) continue;
while (!ans.empty() && ans.back()[0] == elem[0] && ans.back()[1] >= elem[1]) ans.pop_back();
ans.push_back(elem);
}
return ans;
}
array<int, 2> get_max(array<int, 2> a, array<int, 2> b) {
return {max(a[0], b[0]), max(a[1], b[1])};
}
vector<array<int, 2>> apply(vector<array<int, 2>> arr, int mid, int val) {
array<int, 2> mx = {0, 0};
if (val > mid) {
mx[0] = val - mid;
} else {
mx[1] = mid - val;
}
for (auto& elem : arr) {
elem = get_max(elem, mx);
}
return norm(arr);
}
vector<array<int, 2>> mrg(vector<array<int, 2>> a, vector<array<int, 2>> b) {
vector<array<int, 2>> ans;
int idb = -1;
for (int i = 0; i < (int)a.size(); ++i) {
while (idb + 1 < (int)b.size() && b[idb + 1][0] <= a[i][0]) {
++idb;
if (i != 0) {
ans.push_back(get_max(a[i - 1], b[idb]));
}
}
if (idb != -1) {
ans.push_back(get_max(a[i], b[idb]));
}
}
return norm(ans);
}
vector<array<int, 2>> get_max(vector<array<int, 2>> a, vector<array<int, 2>> b) {
vector<array<int, 2>> res;
merge(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res));
return norm(res);
}
array<vector<array<int, 2>>, 4> solve(int mid, const vector<int>& a, int l, int r) {
array<vector<array<int, 2>>, 4> ans;
if (r - l == 1) {
ans[0].push_back({0, 0});
ans[1] = ans[2] = ans[0];
ans[3] = apply(ans[0], mid, a[l]);
return ans;
}
int m = (l + r) / 2;
auto res1 = solve(mid, a, l, m);
auto res2 = solve(mid, a, m, r);
for (int mask = 0; mask < 4; ++mask) {
int maskl = mask & 1;
int maskr = mask & 2;
vector<array<int, 2>> p = mrg(res1[maskl + 2], res2[maskr + 1]);
vector<array<int, 2>> q = apply(mrg(res1[maskl], res2[maskr]), mid, a[m - 1] + a[m]);
ans[mask] = get_max(p, q);
}
return ans;
}
const int INF = 2e9 + 1000;
int solve(int mid, vector<int> a) {
auto res = solve(mid, a, 0, a.size());
int opt = INF;
for (auto elem : res[3]) {
if (elem[0] < INF - elem[1]) {
opt = min(opt, elem[0] + elem[1]);
}
}
return opt;
}
void solve_() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
if (n <= 2) {
cout << "0\n";
return;
}
cout << min(solve(a[0], vector<int>(a.begin() + 1, a.end()))
, solve(a[0] + a[1], vector<int>(a.begin() + 2, a.end()))) << "\n";
}
#define MULTITEST
main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int tst = 1;
#ifdef MULTITEST
cin >> tst;
#endif // MULTITEST
while (tst--) {
solve_();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
3 5 -1 4 2 1 1 4 1 3 2 4 1 7
output:
1 2 0
result:
ok 3 number(s): "1 2 0"
Test #2:
score: -100
Wrong Answer
time: 1301ms
memory: 4940kb
input:
10010 1 1000000000 1 -1000000000 2 1000000000 -1000000000 4 1000000000 1000000000 -1000000000 -1000000000 3 100 -100 100 16 -17 91 -19 66 100 -70 -71 76 -58 99 52 19 25 -67 -63 -32 7 -95 -26 63 -55 -19 77 -100 17 -100 72 -53 -32 8 -100 53 44 -100 -65 -81 -59 100 100 57 -47 1 11 99 10 -100 3 32 2 -26...
output:
0 0 0 0 100 137 129 2000001000 189 84 63 2000001000 237 0 2000001000 135 180 36 200 166 134 0 180 0 72 2000001000 2000001000 0 2000001000 89 2000001000 89 2000001000 135 38 2000001000 96 162 2000001000 2000001000 128 0 38 999804364 196 2000001000 0 2000001000 116 2000001000 0 233 264 54 0 183 200000...
result:
wrong answer 4th numbers differ - expected: '2000000000', found: '0'