QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#190307 | #6134. Soldier Game | woshiluo | WA | 279ms | 14520kb | C++20 | 1.6kb | 2023-09-28 16:57:17 | 2023-09-28 16:57:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<array<long long, 3>> aa;
for (int i = 0; i < n; i++)
aa.emplace_back(array<long long, 3>{a[i], i, 0});
for (int i = 0; i + 1 < n; i++)
aa.emplace_back(array<long long, 3>{a[i] + a[i + 1], i, 1});
sort(aa.begin(), aa.end());
vector<array<array<int, 2>, 2>> t(n * 2);
for (int i = 0; i < n; i++)
t[i + n][1][0] = 1;
auto update = [&](int x) {
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++) {
t[x][i][j] = 0;
for (int k = 0; k < 2; k++)
t[x][i][j] |= t[x * 2][i][k] & t[x * 2 + 1][k][j];
}
};
auto upd = [&](int x, int c, bool k) {
x += n;
t[x][0][c] = k;
while (x >>= 1)
update(x);
};
int j = -1;
long long mn = 2e18 + 1;
for (int i = 0; i < n * 2 - 1; i++) {
auto [v, x, c] = aa[i];
upd(x, c, 1);
while (j + 1 < n * 2 - 1 && t[1][0][0]) {
auto [v2, x2, c2] = aa[j + 1];
upd(x2, c2, 0);
j += 1;
}
if (j >= 0)
mn = min(mn, v - aa[j][0]);
}
cout << mn << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--)
solve();
return 0;
}
/*
1
4
1000000000 1000000000 -1000000000 -1000000000
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
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: 279ms
memory: 14520kb
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 2000000000 100 135 103 181 189 84 163 164 176 0 147 135 152 136 200 131 134 0 136 0 72 171 146 0 183 77 176 89 200 135 38 163 119 126 196 189 70 0 38 999804364 188 161 0 116 124 200 0 101 200 39 0 183 139 0 200 107 153 0 178 85993 199 153 168 163 96 53 107 52 126 47 130 79 0 123 188 173 33 0 8...
result:
wrong answer 11th numbers differ - expected: '63', found: '163'