QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#209420 | #6134. Soldier Game | Sham_Devour | WA | 469ms | 17032kb | C++17 | 1.7kb | 2023-10-10 14:57:43 | 2023-10-10 14:57:44 |
Judging History
answer
#include <cstdio>
#include <iostream>
#include <algorithm>
#define ll long long
#define lson p << 1
#define rson p << 1 | 1
using namespace std;
const int N = 1e5 + 5;
int n, a[N];
struct node {
int val, id, type;
node() {}
node(int _val, int _id, int _type) : val(_val), id(_id), type(_type) {}
} val[N << 1];
struct matrix {
ll a[2][2];
void init() {
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++) a[i][j] = 1e18;
}
} t[N << 2];
matrix operator * (matrix x, matrix y) {
matrix z;
z.init();
for (int k = 0; k < 2; k++)
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++) z.a[i][j] = min(z.a[i][j], max(x.a[i][k], y.a[k][j]));
return z;
}
void pushup(int p) {t[p] = t[lson] * t[rson];}
void build(int p, int l, int r) {
if (l == r) {
t[p].init();
t[p].a[0][1] = 1;
return;
}
int mid = l + r >> 1;
build(lson, l, mid), build(rson, mid + 1, r);
pushup(p);
}
void update(int p, int L, int R, int l, int r, int type) {
if (L == R) return t[p].a[type][0] = r, void();
int mid = L + R >> 1;
if (l <= mid) update(lson, L, mid, l, r, type);
else update(rson, mid + 1, R, l, r, type);
pushup(p);
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
int tot = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
val[++tot] = node(a[i], i, 0);
if (i > 1) val[++tot] = node(a[i] + a[i - 1], i, 1);
}
sort(val + 1, val + 1 + tot, [&](node x, node y) {return x.val < y.val;});
build(1, 1, n);
ll ans = 1e18;
for (int i = tot; i; i--) update(1, 1, n, val[i].id, val[i].val, val[i].type), ans = min(ans, t[1].a[0][0] - val[i].val);
printf("%lld\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5988kb
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: 469ms
memory: 17032kb
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 1 2000000000 100 135 103 181 189 84 101 164 176 0 147 135 152 101 200 131 134 0 136 0 72 171 146 16 183 77 176 101 200 135 38 109 119 126 158 189 70 0 38 999867615 188 161 0 116 116 200 0 101 200 50 1 183 139 36 183 107 139 17 178 85993 126 153 168 163 96 101 96 52 126 72 130 79 0 123 188 173 33...
result:
wrong answer 3rd numbers differ - expected: '0', found: '1'