QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#882927 | #9961. Cows | 08kevin | WA | 1ms | 3840kb | C++14 | 1.6kb | 2025-02-05 13:33:55 | 2025-02-05 13:33:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, l, r, ans;
ll a[200100];
inline bool ok(ll o) {
for (ll i = 1; i <= n; i++) {
if (a[i] > 3 * o) {
return 0;
}
}
ll s = 0;
ll L1 = 0;
ll R1 = 0;
for (ll i = 1; i <= n; i++) {
// if (o == 4) {
// cout << "%" << i - 1 << " " << s << endl;
// }
if (!s) {
s = a[i] - o;
if (s < 0) {
L1 = a[i] + 1;
R1 = o;
}
if (s > 0) {
if (o + o < a[i]) {
return 0;
}
L1 = o - s + 1;
R1 = o;
}
continue;
}
if (s > 0) {
ll x = L1 - 1;
if (x * 2 < a[i]) {
return 0;
}
s = a[i] - x;
if (s < 0) {
L1 = a[i] + 1;
R1 = x;
}
if (s > 0) {
L1 = x - s + 1;
R1 = x;
if (L1 <= 0) {
return 0;
}
}
} else {
ll x = 0;
if (L1 > a[i]) {
x = a[i];
} else {
x = L1 - 1 + max(a[i] - (L1 - 1) + s, (a[i] - (L1 - 1) + 1) / 2);
// x = pos + max((a[i] - pos) + s, (a[i] - pos + 1) / 2);
}
s = x - o;
if (s < 0) {
L1 = x + 1;
R1 = o;
}
if (s > 0) {
L1 = o - s + 1;
R1 = o;
}
}
}
// cout << o << " " << s << endl;
return s <= 0;
}
int main() {
// freopen("cow.in", "r", stdin);
// freopen("cow.out", "w", stdout);
scanf("%lld", &n);
for (ll i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
r = max(r, a[i]);
}
l = 0;
while (l <= r) {
ll mid = (l + r) >> 1;
if (ok(mid)) {
ans = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
printf("%lld\n", ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
input:
5 5 4 0 4 6
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
3 1 4 6
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
1 1000000000
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3840kb
input:
8 6 0 5 5 6 3 0 6
output:
5
result:
wrong answer 1st numbers differ - expected: '4', found: '5'