QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#190292 | #6134. Soldier Game | woshiluo | WA | 295ms | 14476kb | C++20 | 1.7kb | 2023-09-28 16:40:29 | 2023-09-28 16:40:29 |
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;
if (c == 0) {
int y = x + 1;
if (y == 2 * n)
return;
t[y][1][1] = k;
while (y >>= 1)
update(y);
}
while (x >>= 1)
update(x);
};
int j = 0;
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 (t[1][0][0]) {
auto [v2, x2, c2] = aa[j];
mn = min(mn, v - v2);
upd(x2, c2, 0);
j += 1;
}
}
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: 1ms
memory: 3436kb
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: 295ms
memory: 14476kb
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 1000000000 100 69 103 138 110 74 100 115 161 0 138 50 76 100 152 101 114 0 113 0 49 171 146 0 154 77 106 89 165 134 38 109 92 126 168 139 60 0 38 999804364 100 113 0 106 124 177 0 89 148 39 0 139 125 0 200 107 146 0 130 85993 172 133 135 119 100 53 105 52 106 47 71 79 0 107 107 127 33 0 83 199...
result:
wrong answer 4th numbers differ - expected: '2000000000', found: '1000000000'