0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 18:11:59 +00:00

#183. 星空语言

https://sjzezoj.com/submission/7446
This commit is contained in:
Baoshuo Ren 2021-01-02 21:50:58 +08:00 committed by Baoshuo Ren
parent 8675f83812
commit 0ca41bd4e4
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

50
S2OJ/183/183.cpp Normal file
View File

@ -0,0 +1,50 @@
#include <bits/stdc++.h>
using namespace std;
int n, a[110], i;
bool t1, t2;
long long l = 0, r = 1000000000, mid, t[110], top;
bool check(long long x) {
top = 0;
for (i = 1; i < n; i++) {
if (a[i] == -1) {
t[++top] = x;
}
else if (a[i] > 0) {
t[++top] = a[i];
}
else if (top > 1) {
t[top - 1] += t[top];
top--;
}
}
return t[top] <= a[n];
}
int main() {
while (cin >> a[++n]) {}
n--;
t1 = check(0);
if (t[top] == a[n]) {
cout << 0 << endl;
return 0;
}
t2 = check(1000000001);
if (t1 == t2) {
cout << -1 << endl;
return 0;
}
while (l < r) {
mid = l + r + 1 >> 1;
if (check(mid)) {
l = mid;
}
else {
r = mid - 1;
}
}
cout << l << endl;
return 0;
}