text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t = 0, sl = 0;
char s[100010];
cin >> s;
for (int i = 0; i < strlen(s); i++)
if (s[i] == '#') {
t++;
} else if (s[i] == '(')
sl++;
else
sl--;
if (sl <= 0)
cout << "-1";
else {
int t1 = 0, t2 = 0;
for (int i = 0; i < strlen(s); i++) {
if (s[i] == '#') {
t1++;
if (t1 != t) {
t2--;
} else
t2 = t2 - sl + t - 1;
} else if (s[i] == '(')
t2++;
else
t2--;
if (t2 < 0) {
cout << "-1";
return 0;
}
}
for (int i = 1; i < t; i++) cout << '1' << endl;
cout << sl - t + 1;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int a = 0, l, x, y, ind;
vector<int> res;
cin >> s;
l = s.length();
if (s[l - 1] == '(') {
cout << -1 << endl;
return 0;
}
for (int i = 0; i < l; i++) {
if (s[i] == '(')
a++;
else if (s[i] == ')') {
a--;
if (a < 0) {
cout << -1 << endl;
return 0;
}
} else {
if (a <= 0) {
cout << -1 << endl;
return 0;
} else {
x = a;
ind = i;
res.push_back(1);
a--;
}
}
}
if (a < 0) {
cout << -1 << endl;
return 0;
} else if (a > 0) {
if (a <= x) {
res[res.size() - 1] += a;
} else {
cout << -1 << endl;
return 0;
}
}
for (int i = 0; i < res.size(); i++) {
cout << res[i] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main() {
string str;
cin >> str;
int n = str.length();
int l = 0, r = 0, s = 0;
for (int i = 0; i < n; i++) {
if (str[i] == '(') l++;
if (str[i] == ')') r++;
if (str[i] == '#') s++;
}
if (s + r > l) {
cout << -1 << endl;
return 0;
}
int L = 0, R = 0, S = 0;
for (int i = 0; i < n; i++) {
if (str[i] == '(') L++;
if (str[i] == ')') R++;
if (str[i] == '#' && L == 0) {
cout << -1 << endl;
return 0;
}
if (str[i] == '#' && L > 0) {
R++;
L--;
a[S++] = 1;
}
}
a[S - 1] = l - r - s + 1;
l = 0, r = 0, s = 0;
for (int i = 0; i < n; i++) {
if (r > l) {
cout << -1 << endl;
return 0;
}
if (str[i] == '(') l++;
if (r > l) {
cout << -1 << endl;
return 0;
}
if (str[i] == ')') r++;
if (r > l) {
cout << -1 << endl;
return 0;
}
if (str[i] == '#') r += a[s++];
}
for (int i = 0; i < S; i++) {
cout << a[i] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string s;
int n;
int b;
int lp;
string p;
int cnt;
int main() {
cin >> s;
n = s.size();
int lp = n - 1;
for (int i = 0; i < n; i++)
if (s[i] == '(')
b++;
else if (s[i] == ')')
b--;
else if (s[i] == '#')
cnt++;
while (s[lp] != '#') {
lp--;
}
int sb = b;
for (int i = 0; i < n; i++) {
if (s[i] != '#') {
p = p + s[i];
} else {
if (i != lp) {
p = p + ')';
b--;
} else {
for (int o = 0; o < max(b, 1); o++) p = p + ')';
b = 0;
}
}
}
for (int i = 0; i < p.size(); i++) {
if (p[i] == '(')
b++;
else
b--;
if (b < 0) {
cout << "-1";
return 0;
}
}
if (b == 0) {
for (int i = 0; i < cnt - 1; i++) {
cout << "1" << endl;
sb--;
}
cout << sb;
} else {
cout << "-1";
}
}
|
#include <bits/stdc++.h>
using namespace std;
string str;
int diez, q, z, n, p, pos;
int ans[100005];
int main() {
cin >> str;
n = str.size();
for (int k = 0; k < str.size(); k++) {
if (str[k] == '(') q++;
if (str[k] == ')') q--;
if (str[k] == '#') diez++;
}
q -= diez;
if (q < 0) {
cout << "-1" << endl;
return 0;
}
for (int k = n - 1; k >= 1; k--) {
if (str[k] == '#') {
p = q + 1;
pos = k;
break;
}
}
q = 0;
for (int k = 0; k < str.size(); k++) {
if (str[k] == '(') q++;
if (str[k] == ')') q--;
if (str[k] == '#' && k != pos) q--;
if (str[k] == '#' && k == pos) q -= p;
if (q < 0) {
cout << "-1" << endl;
return 0;
}
}
for (int k = 2; k <= diez; k++) {
cout << 1 << endl;
}
cout << p << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int maxn = 1e5 + 5;
const long long int inf = 1e9;
const long double PI = acos(-1);
void yes() { cout << "YES"; }
void no() { cout << "NO"; }
long long int pmod(long long int a, long long int mod = 1000000007) {
return ((a) % mod + mod) % mod;
}
long long int cel(long long int x1, long long int y1) {
if ((x1) <= 0) {
return (x1) / (y1);
}
return (((x1) / (y1)) + (((x1) % (y1)) != 0));
}
long long int gcd(long long int a, long long int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
return (a / gcd(a, b)) * b;
}
long long bp(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
long long bpm(long long a, long long b, long long m = 1000000007) {
if (a >= m) a %= m;
long long res = 1;
while (b > 0) {
if (b & 1) res *= a;
if (res >= m) res %= m;
a *= a;
if (a >= m) a %= m;
b >>= 1;
}
if (res >= m) res %= m;
return res;
}
string vow = "aeiou";
const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};
const int dxk[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dyk[] = {0, 1, 0, -1, -1, 1, -1, 1};
const int dxh[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyh[] = {1, -1, 2, -2, 2, -2, 1, -1};
const int p = 31;
const int m = 1e9 + 9;
vector<vector<bool>> in;
vector<vector<int>> out;
void solve() {
string s;
cin >> s;
int sum = 0;
int n = ((s).size());
for (int i = 0; i < n; i++) {
if (s[i] == '(')
sum++;
else
sum--;
if (sum < 0) {
cout << -1;
return;
}
}
int idx = -1;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '#') {
idx = i;
cnt++;
}
}
int sum1 = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '(')
sum1++;
else if (i == idx) {
sum1 = sum1 - (sum + 1);
} else
sum1--;
if (sum1 < 0) {
cout << -1;
return;
}
}
for (int i = 0; i < cnt - 1; i++) cout << 1 << "\n";
cout << sum + 1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
;
int t = 1;
while (t--) {
solve();
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int hsh, cnt, indx;
char str[100005];
vector<int> v;
int main() {
scanf("%s", str);
for (int i = 0; str[i] != '\0'; ++i) {
if (str[i] == '#') {
if (cnt >= 1)
v.push_back(1), --cnt;
else
exit(puts("-1"));
} else if (str[i] == ')')
--cnt;
else
++cnt;
if (cnt < 0) exit(puts("-1"));
}
v.back() = ++cnt;
cnt = 0;
for (int i = 0; str[i] != '\0'; ++i) {
if (str[i] == '(')
++cnt;
else if (str[i] == ')')
--cnt;
else
cnt -= v[indx++];
if (cnt < 0) exit(puts("-1"));
}
if (cnt > 0) exit(puts("-1"));
for (int i = 0; i < v.size(); ++i) printf("%d\n", v[i]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
string s;
cin >> s;
int total = 0, pos = 0;
for (int i = 0; i < s.length(); i++) {
total += s[i] == '(' ? 1 : -1;
if (s[i] == '#') {
pos = i;
}
}
if (total < 0) {
cout << -1;
return 0;
}
int last = 1 + total;
total = 0;
for (int i = 0; i < s.length(); i++) {
total += i == pos ? -last : (s[i] == '(' ? 1 : -1);
if (total < 0) {
cout << -1;
return 0;
}
}
if (total) {
cout << -1;
return 0;
}
for (int i = 0; i < s.length(); i++) {
if (s[i] == '#') {
if (i == pos) {
cout << last << "\n";
} else {
cout << 1 << "\n";
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char s[1234567];
int main() {
scanf("%s", s);
int n = strlen(s);
int total = 0;
int pos = -1;
for (int i = 0; i < n; i++) {
total += (s[i] == '(' ? 1 : -1);
if (s[i] == '#') {
pos = i;
}
}
if (total < 0) {
printf("%d\n", -1);
return 0;
}
int last = 1 + total;
total = 0;
for (int i = 0; i < n; i++) {
total += (i == pos ? -last : (s[i] == '(' ? 1 : -1));
if (total < 0) {
printf("%d\n", -1);
return 0;
}
}
for (int i = 0; i < n; i++) {
if (s[i] == '#') {
if (i == pos) {
printf("%d\n", last);
} else {
printf("%d\n", 1);
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a, s, d, f, g, h, j, k, l, i, n, m;
string x;
int main() {
cin >> x;
for (i = 0; i < x.size(); i++) {
if (x[i] == '(')
d++;
else
d--;
if (x[i] == '#') j++;
}
if (d < 0) {
cout << -1;
return 0;
}
for (i = 0; i < x.size(); i++) {
if (x[i] == '(')
k++;
else
k--;
if (x[i] == '#') {
a++;
if (a == j) {
f = d + 1;
k = k - d;
}
}
if (k < 0) {
cout << -1;
return 0;
}
}
if (k != 0) {
cout << -1;
return 0;
}
for (i = 0; i < a - 1; i++) {
cout << 1 << endl;
}
cout << f;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
while (TESTS--) {
long long cnt = 0;
std::vector<char> v;
string s;
cin >> s;
long long n = s.length(), siz = 0, last = -1;
for (long long i = 0; i < n; i++)
if (s[i] == '#') last = i;
for (long long i = 0; i < last + 1; i++) {
if ((s[i] == ')') && (v.empty())) {
cout << -1;
return 0;
} else if (s[i] == ')') {
v.pop_back();
siz--;
if (cnt > siz) {
cout << -1;
return 0;
}
} else if (s[i] == '(') {
siz++;
v.push_back('(');
} else {
cnt++;
if (cnt > siz) {
cout << -1;
return 0;
}
}
}
vector<char> v2;
for (long long i = last + 1; i < n; i++) {
if ((s[i] == ')') && (!v2.empty()) && (v2.back() == '('))
v2.pop_back();
else
v2.push_back(s[i]);
}
if ((!v2.empty()) && (v2.back() == '(')) {
cout << -1;
return 0;
} else {
if (cnt + (long long)v2.size() > siz) {
cout << -1;
return 0;
}
}
long long c = 0, t = (long long)v2.size();
for (long long i = 0; i < n; i++) {
if (s[i] == '(') c++;
if (s[i] == ')') c--;
if (s[i] == '#') {
cnt--;
if (cnt == 0) {
c -= t;
cout << c << '\n';
} else {
c--;
cout << 1 << '\n';
}
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string s;
int l, _, p, t;
int main() {
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '(') l++;
if (s[i] == ')') l--;
if (s[i] == '#') l--, _++;
if (l < 0) {
cout << -1;
return 0;
}
}
for (int i = 0; i < s.size(); i++) {
if (s[i] == '#') {
t++;
if (t == _) p -= l;
p--;
}
if (s[i] == '(') p++;
if (s[i] == ')') p--;
if (p < 0) {
cout << "-1";
return 0;
}
}
for (int i = 1; i < _; i++) cout << "1\n";
cout << 1 + l;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[100004];
cin >> str;
int ans = 0;
int n = strlen(str), y = 0, x = 0;
int hs = 0, last = -1;
for (int i = 0; i < n; i++) {
if (str[i] == '#') {
hs++;
last = i;
y++;
}
if (str[i] == ')') {
y++;
}
if (str[i] == '(') {
x++;
}
}
if (x < y) {
cout << -1 << endl;
return 0;
}
int tx = x, ty = y;
x = 0, y = 0;
for (int i = 0; i < n; i++) {
if (str[i] == '#') {
y++;
}
if (str[i] == '(') {
x++;
}
if (str[i] == ')') {
y++;
}
if (y > x) {
cout << -1;
return 0;
}
if (i == last) {
if (tx - ty >= 0 && tx - ty + y <= x) {
ans = tx - ty + 1;
y += tx - ty;
} else {
cout << -1;
return 0;
}
}
}
for (int i = 0; i < hs - 1; i++) {
cout << 1 << endl;
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool umax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
int arr[100009];
int main() {
string a;
cin >> a;
int a1 = 0, a2 = 0, a3 = 0, c;
vector<int> v;
for (int i = 0; i < a.size(); i++) {
if (a[i] == '(')
a1++;
else if (a[i] == ')')
a2++;
else
a3++;
}
if (a2 + a3 > a1)
cout << "-1" << endl;
else {
vector<int> v;
for (int i = 1; i < a3; i++) v.push_back(1);
a2 += (a3 - 1);
v.push_back(a1 - a2);
a1 = a2 = c = 0;
for (int i = 0; i < a.size(); i++) {
if (a[i] == '#')
a2 += v[c++];
else if (a[i] == ')')
a2++;
else
a1++;
if (a2 > a1) {
cout << "-1" << endl;
return 0;
}
}
for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename X>
ostream& operator<<(ostream& x, const vector<X>& v) {
for (long long i = 0; i < v.size(); ++i) x << v[i] << " ";
return x;
}
template <typename X>
ostream& operator<<(ostream& x, const set<X>& v) {
for (auto it : v) x << it << " ";
return x;
}
template <typename X, typename Y>
ostream& operator<<(ostream& x, const pair<X, Y>& v) {
x << v.ff << " " << v.ss;
return x;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
for (auto it : v) os << it.first << "=>" << it.second << endl;
return os;
}
struct pair_hash {
inline std::size_t operator()(
const std::pair<long long, long long>& v) const {
return v.first * 31 + v.second;
}
};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
int main() {
string s;
cin >> s;
int n = s.size();
vector<long long> ind;
bool vis[n];
memset(vis, false, sizeof vis);
for (long long i = 0; i < n; i++)
if (s[i] == '#') {
ind.push_back(i);
vis[i] = true;
}
string ss = s;
int cl = 0;
for (long long i = 0; i < n; i++) {
if (vis[i]) {
ss[i] = ')';
cl++;
}
if (s[i] == ')') {
cl++;
}
}
if (cl > n - cl) {
cout << -1 << endl;
return 0;
}
int xp = 0;
for (long long i = 0; i < n; i++) {
if (s[i] == '(') {
xp++;
} else {
xp--;
if (xp < 0) {
cout << -1 << endl;
return 0;
}
}
}
int sf[n];
sf[n - 1] = vis[n - 1];
for (int i = n - 2; i >= 0; i--) {
sf[i] = sf[i + 1] + vis[i];
}
bool ff = true;
xp = 0;
for (int i = n - 1; i >= 0; i--) {
if (s[i] == ')') {
xp++;
} else {
xp--;
}
if (xp < 0) {
if (sf[i] == 0) ff = false;
break;
}
}
if (!ff) {
cout << -1 << endl;
return 0;
}
for (long long i = 0; i < ind.size() - 1; i++) {
cout << 1 << endl;
}
cout << 1 + n - cl - cl << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
char s[200100];
void printno() {
printf("%d\n", -1);
exit(0);
}
int number[200100];
int main() {
scanf("%s", s);
int len = (int)strlen(s);
int num1 = 0, num2 = 0, num3 = 0;
for (int i = 0; i < len; i++) {
if (s[i] == '(')
num1 += 1;
else if (s[i] == ')')
num2 += 1;
else
num3 += 1;
}
if (num2 + num3 > num1) printno();
bool first = true;
int d = num1 - (num2 + num3);
for (int i = len - 1; i >= 0; i--) {
if (s[i] == '#') {
if (first) {
first = false;
number[i] = 1 + d;
} else {
number[i] = 1;
}
} else {
number[i] = 1;
}
}
d = 0;
for (int i = 0; i < len; i++) {
if (s[i] == '(')
d -= number[i];
else
d += number[i];
if (d > 0) printno();
}
for (int i = 0; i < len; i++) {
if (s[i] == '#') {
printf("%d\n", number[i]);
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
char a[100010];
int ans[100010], len = 0, num[100010];
int main() {
scanf("%s", a);
int n = strlen(a);
int l = 0, r = 0;
int tmp = 0;
for (int i = n - 1; i >= 0; i--) {
if (a[i] == '(') tmp--;
if (a[i] == ')' || a[i] == '#') tmp++;
num[i] = tmp;
if (tmp < 0) tmp = 0;
}
len = 0;
for (int i = 0; i < n; i++) {
if (l < r) {
puts("-1");
return 0;
}
if (a[i] == '(') l++;
if (a[i] == ')') r++;
if (a[i] == '#') {
ans[len++] = l - r - num[i];
r += ans[len - 1] + 1;
}
}
if (l != r) {
puts("-1");
return 0;
}
for (int i = 0; i < len; i++) {
if (ans[i] + 1 <= 0) {
puts("-1");
return 0;
}
}
for (int i = 0; i < len; i++) {
printf("%d\n", ans[i] + 1);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
template <class T>
inline bool fs(T &x) {
int c = getchar();
int sgn = 1;
while (~c && c < '0' || c > '9') {
if (c == '-') sgn = -1;
c = getchar();
}
for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
x *= sgn;
return ~c;
}
string s;
int ara[100000 + 5], n;
int main() {
int a, b, c, d, e, f, i, j;
cin >> s;
n = s.size();
a = b = d = 0;
for (i = 0; i < n; i++) {
if (s[i] == '(')
a++, d++;
else
a--, d = 0;
ara[i] = a;
if (a < 0) b = 1;
}
if (d != 0) b = 1;
vector<int> v;
a = 0;
for (i = n - 1; i >= 0; i--) {
if (s[i] == '#') {
if (ara[i] - a >= 0) {
c = ara[i] - a + 1;
a += c;
v.push_back(c);
} else
b = 1;
} else if (s[i] == ')')
a++;
else
a--;
if (a < 0) b = 1;
}
if (b == 1) {
printf("-1\n");
return 0;
}
reverse(v.begin(), v.end());
for (i = 0; i < v.size(); i++) printf("%d\n", v[i]);
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
using namespace std;
bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); }
void solve() {
string str;
cin >> str;
long long int n = str.size(), count = 0, hash = 0;
for (long long int i = 0; i < n; ++i) {
if (count < 0) {
cout << "-1\n";
return;
}
if (str[i] == '(')
count++;
else if (str[i] == ')')
count--;
else
hash++;
}
if (count >= hash) {
long long int c = 0, x = 0;
for (long long int i = 0; i < n; ++i) {
if (c < 0) {
cout << "-1\n";
return;
}
if (str[i] == '(')
c++;
else if (str[i] == ')')
c--;
else {
x++;
if (x == hash)
c -= (count - hash + 1);
else
c--;
}
}
for (long long int i = 1; i < hash; ++i) cout << "1\n";
cout << count - hash + 1;
} else
cout << "-1\n";
}
int32_t main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
while (T--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, l = "";
cin >> s;
string t = "";
int k = 0, tb = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '#') {
t += ")#";
tb++;
k--;
} else {
t += s[i];
if (s[i] == '(')
k++;
else
k--;
}
}
if (k < 0) {
printf("-1");
return 0;
}
int tbbb = tb;
int cur = 0;
for (int i = 0; i < t.length(); i++) {
if (t[i] == '(') {
cur++;
l += '(';
} else if (t[i] == ')') {
cur--;
l += ')';
} else {
tb--;
if (tb == 0) {
for (int i = 0; i < k; i++) l += ')';
}
}
if (cur < 0) {
printf("-1");
return 0;
}
}
cur = 0;
for (int i = 0; i < l.length(); i++) {
if (l[i] == '(') {
cur++;
} else if (l[i] == ')') {
cur--;
}
if (cur < 0) {
printf("-1");
return 0;
}
}
for (int i = 0; i < tbbb - 1; i++) {
printf("1\n");
}
printf("%d", k + 1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 100;
char s[maxn];
int cnt[maxn];
int vis[maxn];
stack<int> S;
int main() {
scanf("%s", s);
int len = strlen(s);
int ok = 1;
for (int i = 0; i < len; i++) {
if (s[i] == '(')
S.push(i);
else if (S.empty()) {
ok = 0;
break;
} else {
int u = S.top();
S.pop();
vis[u] = 1;
}
if (s[i] == '#') cnt[i]++;
}
int j;
for (int i = 0; i < len; i = j + 1) {
int tmp = 0;
j = i;
while (j < len && s[j] != '#') {
tmp += !vis[j] && s[j] == '(';
j++;
}
if (j == len && tmp) {
ok = 0;
break;
}
cnt[j] += tmp;
}
if (!ok)
puts("-1");
else
for (int i = 0; i < len; i++)
if (cnt[i]) printf("%d\n", cnt[i]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline void use_io_optimizations() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
use_io_optimizations();
string s;
cin >> s;
int left = 0;
int right = 0;
int holes = 0;
int last_hole = 0;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '(') {
++left;
} else if (s[i] == ')') {
++right;
} else {
++holes;
last_hole = i;
}
}
int dif = 0;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '(') {
++dif;
} else if (s[i] == ')') {
--dif;
} else {
if (i == last_hole) {
dif -= max(left - right - holes + 1, 1);
} else {
--dif;
}
}
if (dif < 0) {
cout << -1 << '\n';
return 0;
}
}
for (int i = 0; i < holes; ++i) {
if (i < holes - 1) {
cout << "1\n";
} else {
cout << left - right - holes + 1 << '\n';
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
int a[100000 + 5];
int n = 0;
int ob = 0, cb = 0;
for (long long i = 0; i < s.length(); ++i) {
if (s[i] == '(') {
a[i] = 1;
++ob;
} else if (s[i] == ')') {
a[i] = -1;
++cb;
} else if (s[i] == '#') {
++n;
}
}
if (ob - cb - n + 1 < 1) {
cout << -1;
return 0;
}
int k = 0;
for (int i = s.length() - 1; i >= 0; --i) {
if (s[i] == '#') {
if (k == 0) {
a[i] = -(ob - cb - n + 1);
} else {
a[i] = -1;
}
++k;
}
}
int ans = 0;
for (long long i = 0; i < s.length(); ++i) {
ans += a[i];
if (ans < 0) {
cout << -1;
return 0;
}
}
for (long long i = 0; i < n - 1; ++i) cout << 1 << endl;
cout << ob - cb - n + 1;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
void solve() {
string s;
cin >> s;
int n = s.length();
int total = 0, count = 0;
int pos = -1, last;
for (int i = 0; i < n; i++) {
if (s[i] == '(')
total++;
else {
if (s[i] == '#') {
pos = i;
count++;
}
total--;
}
if (total < 0) {
cout << -1 << "\n";
return;
}
}
last = 1 + total;
total = 0;
for (int i = 0; i < n; i++) {
if (i == pos) {
total -= last;
} else {
if (s[i] == '(')
total++;
else
total--;
}
if (total < 0) {
cout << -1 << "\n";
return;
}
}
for (int i = 0; i < count - 1; i++) {
cout << 1 << "\n";
}
cout << last << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
char a[1000000];
int ans[1000000];
int main() {
while (~scanf("%s", a)) {
memset(ans, 0, sizeof(ans));
int n = strlen(a);
int flag = 0;
int zuo = 0;
int cont = 0;
int contz = 0;
int tmpp = 0;
for (int i = 0; i < n; i++) {
if (a[i] == '#') contz++;
if (a[i] == '(') tmpp++;
if (a[i] == ')') {
if (tmpp > 0)
tmpp--;
else {
tmpp = -1;
break;
}
}
}
if (tmpp == -1) {
printf("-1\n");
continue;
}
for (int i = 0; i < n; i++) {
if (a[i] == '(') {
zuo++;
} else if (a[i] == ')') {
if (zuo > 0) zuo--;
} else {
if (zuo > 0) {
if (cont + 1 != contz) {
ans[cont++] = 1;
zuo--;
} else {
for (int j = n - 1; j > i; j--) {
if (a[j] == ')') zuo--;
if (a[j] == '(') zuo++;
}
ans[cont++] = zuo;
zuo = 0;
}
} else
flag = 1;
}
}
if (flag == 1 || zuo != 0) {
printf("-1\n");
} else {
int tag = 0;
for (int i = 0; i < contz; i++) {
if (ans[i] == 0 || ans[i] < 0) tag = 1;
}
if (tag == 1) {
printf("-1\n");
} else {
for (int i = 0; i < contz; i++) {
printf("%d\n", ans[i]);
}
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
#pragma comment(linker, "/STACK:268435456")
char c1[111111];
vector<int> r(111111, 0);
int i, no = 0, nc = 0, x = 0, c, p, x1 = 0, x2 = 0;
string s;
gets(c1);
s = c1;
for (i = 0; i < s.length(); i++) {
if (s[i] == '(') no++;
if (s[i] == ')') nc++;
if (s[i] == '#') {
x++;
p = i;
}
if (nc + x > no) {
printf("-1");
return 0;
}
}
c = no - nc;
no = 0;
nc = 0;
int t = 0;
for (i = 0; i < s.length(); i++) {
if (s[i] == '#') t++;
if (s[i] == '(') no++;
if (s[i] == ')') nc++;
if (t == x) {
if (nc + c > no) {
printf("-1");
return 0;
}
}
}
p++;
while (p < s.length()) {
if (s[p] == '(')
x1++;
else
x2++;
p++;
}
if (x1 > x2) {
printf("-1");
return 0;
}
for (i = 0; i < (x - 1); i++) {
printf("1\n");
c--;
}
printf("%d", c);
return 0;
}
|
#include <bits/stdc++.h>
int MOD = 1013;
using namespace std;
int i, j, n, m, k;
int main() {
string s, ss;
cin >> s;
int a = 0, b = 0;
string t = "";
int last = -1;
int cnt = 0;
for (i = 0; i < s.size(); i++) {
if (s[i] == '(')
a++;
else
a--;
if (s[i] == '#') {
cnt++;
t += ')';
last = i;
} else
t += s[i];
}
s = "";
for (i = 0; i < t.size(); i++) {
if (i == last)
for (j = 0; j < a; j++) s += ')';
s += t[i];
}
b = 0;
for (i = 0; i < s.size(); i++) {
if (s[i] == '(')
b++;
else
b--;
if (b < 0) {
cout << -1 << endl;
return 0;
}
}
if (b != 0) {
cout << -1 << endl;
return 0;
}
for (i = 0; i < cnt - 1; i++) puts("1");
cout << a + 1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
long long i, j, a = 0, b = 0;
for (i = 0; i < s.size(); i++) {
if (s[i] == '(')
a++;
else if (s[i] == ')')
a--;
if (s[i] == '#') b++;
if (a < b) {
cout << "-1";
return 0;
}
}
vector<long long> v;
for (i = 0; i < b - 1; i++) {
v.push_back(1);
a--;
}
v.push_back(a);
j = 0;
string t;
for (i = 0; i < s.size(); i++) {
if (s[i] == '#') {
for (long long k = 0; k < v[j]; k++) {
t.push_back(')');
}
j++;
} else
t.push_back(s[i]);
}
a = 0;
for (i = 0; i < t.size(); i++) {
if (t[i] == '(')
a++;
else
a--;
if (a < 0) {
cout << "-1";
return 0;
}
}
if (a > 0) {
cout << "-1";
return 0;
} else {
for (i = 0; i < v.size(); i++) cout << v[i] << endl;
}
}
|
#include <bits/stdc++.h>
const long long inf = 1e9;
const long long mod = 1e9 + 7;
const long long zero = 0;
const long long maxn = 1e5 + 5;
using namespace std;
string s;
long long p, t, cnt;
long long tl, tr, o;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '#') p = i, o++;
}
for (int i = 0; i < p; i++) {
if (s[i] == '#') s[i] = ')';
}
for (int i = p + 1; i < s.size(); i++) {
if (s[i] == '(')
cnt--;
else
cnt++;
}
if (cnt < 0) {
cout << -1 << endl;
return 0;
}
for (int i = 0; i <= s.size(); i++) {
if (s[i] == '(')
tl++;
else if (s[i] == ')')
tr++;
}
cnt = tl - tr;
if (cnt <= 0) {
cout << -1 << endl;
return 0;
}
for (int i = 0; i < s.size(); i++) {
if (s[i] == '(') {
t++;
} else if (s[i] == ')') {
t--;
if (t < 0) {
cout << -1 << endl;
return 0;
}
} else {
t -= cnt;
if (t < 0) {
cout << -1 << endl;
return 0;
}
}
}
for (int i = 1; i < o; i++) cout << 1 << endl;
cout << cnt << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string s;
int x, y, ans, t, a, b;
int main() {
int i, j;
t = -1;
cin >> s;
for (i = 0; i < s.size(); i++) {
if (s[i] == '#') {
ans++;
t = i;
}
if (s[i] == '(') y++;
if (s[i] == ')') x++;
}
if (x + ans > y) return !(printf("-1"));
for (i = 0; i < s.size(); i++) {
if (s[i] == '(')
b++;
else {
if (i != t) {
a++;
if (a > b) return !(printf("-1"));
} else {
a += (y - x - ans + 1);
if (a > b) return !(printf("-1"));
}
}
}
for (i = 1; i < ans; i++) printf("1\n");
printf("%d", y - x - ans + 1);
}
|
#include <bits/stdc++.h>
using namespace std;
const int M = (int)1e8 + 7;
int main() {
string s;
cin >> s;
int n = (s).size();
string ans;
int x = 0;
int o = 0;
int c = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '(') o++;
if (s[i] == ')') {
c++;
}
if (s[i] == '#') {
x = i;
c++;
}
}
int balance = 0;
if (o - c + 1 <= 0) {
cout << -1;
return 0;
}
for (int i = 0; i < (s).size(); ++i) {
if (s[i] == '#') {
if (i != x) {
balance--;
ans += ')';
} else {
for (int j = 0; j < o - c + 1; ++j) {
ans += ')';
balance--;
}
}
} else if (s[i] == '(') {
ans += '(';
balance++;
} else {
ans += ')';
balance--;
}
if (balance < 0) {
cout << -1;
return 0;
}
}
for (int i = 0; i < (s).size(); ++i) {
if (s[i] == '#') {
if (x != i)
cout << 1 << endl;
else {
cout << o - c + 1 << endl;
}
}
}
}
|
#include <bits/stdc++.h>
const int MAXN = 100010;
using namespace std;
int N;
char str[MAXN];
vector<int> seq;
int main() {
cin >> str;
N = strlen(str);
int last;
for (int i = N - 1; i >= 0; i--)
if (str[i] == '#') {
last = i;
break;
}
int cur = 0;
for (int i = 0; i < N; i++) {
if (str[i] == '(')
cur++;
else if (str[i] == ')')
cur--;
else if (str[i] == '#') {
cur--;
if (i != last) seq.push_back(1);
}
if (cur < 0) {
printf("-1\n");
return 0;
}
}
seq.push_back(cur + 1);
cur = 0;
int pos = 0;
for (int i = 0; i < N; i++) {
if (str[i] == '(')
cur++;
else if (str[i] == ')')
cur--;
else
cur -= seq[pos++];
if (cur < 0) {
printf("-1\n");
return 0;
}
}
for (int i = 0; i < seq.size(); i++) cout << seq[i] << '\n';
return 0;
}
|
#include <bits/stdc++.h>
const int Max_N = 9 + (int)1e5;
char s[Max_N];
int ans[Max_N];
int main() {
scanf("%s", s);
int n = strlen(s), t1 = 0, t2 = 0, last = n;
for (int i = n - 1; i >= 0; --i)
if (s[i] == '#') {
last = i;
break;
}
for (int i = 0; i < n; ++i) {
if (s[i] == '(')
++t1;
else
++t2;
}
if (t1 < t2) return puts("-1"), 0;
int cnt = 0, tot = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '(')
++cnt;
else if (i == last) {
cnt -= 1 + t1 - t2;
ans[tot++] = 1 + t1 - t2;
} else {
--cnt;
if (s[i] == '#') ans[tot++] = 1;
}
if (cnt < 0) return puts("-1"), 0;
}
for (int i = 0; i < tot; ++i) printf("%d\n", ans[i]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
if (str[0] == ')' || str[0] == '#' || str[str.size() - 1] == '(') {
cout << "-1";
return 0;
}
int countOp = 0, countClo = 0, countSym = 0, count = 0, aux, c = 0;
for (int i = 0; i < str.size(); i++) {
if (str[i] == '(') {
if (c == 0) {
countSym = 0;
}
c++;
countOp++;
} else if (str[i] == ')') {
c--;
countClo++;
} else {
countSym++;
c--;
count++;
}
if (c < 0) {
cout << "-1";
return 0;
}
}
int dif = countOp - countClo;
aux = count;
if (dif == 0 || dif < 0 || dif < countSym) cout << "-1" << endl;
if (countSym == 0)
cout << "-1" << endl;
else {
for (int i = 0; i < count; i++) {
if (i == (count - 1) && dif > 0) {
cout << dif--;
break;
}
dif--;
cout << "1" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
long long cnt = 0, cnt1 = 0;
std::vector<long long> v;
for (long long i = 0; i < s.length(); i++) {
if (s[i] == '(')
cnt++;
else
cnt--;
if (s[i] == '#') v.push_back(1);
if (cnt < 0 or cnt1 < 0) {
cout << "-1";
return 0;
}
}
for (long long i = s.length() - 1; i >= 0; i--) {
if (s[i] == ')')
cnt1++;
else if (s[i] == '(')
cnt1--;
else
cnt1 += s.length();
if (cnt1 < 0) {
cout << "-1";
return 0;
}
}
v[v.size() - 1] += cnt;
for (long long i = 0; i < v.size(); i++) cout << v[i] << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char a[100005];
int n;
int ans[100005][2];
int flag[100005];
int find_mn(int pos) {
int mn = 1000000;
for (int i = pos; i < n; i++) {
mn = min(mn, flag[i]);
}
return mn;
}
int main() {
cin >> a;
int i, rest = 0, cnt = 0;
n = strlen(a);
for (i = 0; i < n; i++) {
if (a[i] == '(')
rest++;
else if (a[i] == ')')
rest--;
else if (a[i] == '#') {
ans[cnt][0] = 1;
ans[cnt++][1] = i;
rest--;
}
if (rest < 0) {
cout << -1 << endl;
return 0;
}
flag[i] = rest;
}
if (rest < 0) {
cout << -1 << endl;
} else {
int mn = find_mn(ans[cnt - 1][1]);
if (mn < rest) {
cout << -1 << endl;
return 0;
} else
ans[cnt - 1][0] += rest;
for (i = 0; i < cnt; i++) cout << ans[i][0] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int N;
char str[100000 + 5];
void solve() {
int a, lastSharp = -1, sharps = 0;
for (int i = 0; i < N; i++)
if (str[i] == '#') {
sharps++;
lastSharp = i;
}
a = 0;
for (int i = 0; i < N; i++) {
if (i != lastSharp) {
if (str[i] == '#')
a--;
else
a += (str[i] == '(') ? 1 : -1;
if (a < 0) {
printf("-1\n");
return;
}
}
}
int b = 0;
for (int i = 0; i < N; i++) {
if (i != lastSharp) {
if (str[i] == '#')
b--;
else
b += (str[i] == '(') ? 1 : -1;
} else
b -= max(a, 1);
if (b < 0) {
printf("-1\n");
return;
}
}
for (int i = 1; i < sharps; i++) printf("1\n");
printf("%d\n", a);
}
int main() {
scanf("%s", str);
N = strlen(str);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int noh = 0, cb = 0;
for (int i = 0; s[i]; i++) {
if (s[i] == '#') noh++;
if (s[i] == '(') cb++;
if (s[i] == ')') cb--;
if (cb - noh + 1 <= 0) {
cout << "-1";
return 0;
}
}
if (noh > cb) {
cout << "-1";
return 0;
}
int o = 0;
for (int i = s.size() - 1; s[i] != '#'; i--) {
if (s[i] == '(')
o--;
else
o++;
if (o < 0) {
cout << "-1";
return 0;
}
}
for (int i = 1; i < noh; i++) cout << "1" << endl;
cout << cb - (noh - 1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s;
cin >> s;
int n = (int)s.size();
int cnt = 0;
bool pos = true;
vector<int> h;
int re[n];
memset(re, 0, sizeof(re));
int k = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '#') {
cnt++;
h.push_back(i);
}
if (s[i] != '(')
k--;
else
k++;
if (k < 0) pos = false;
}
for (int i = 0; i < (int)h.size(); i++) {
if (i == (int)h.size() - 1)
re[h[i]] = k + 1;
else
re[h[i]] = 1;
}
k = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '(')
k++;
else if (s[i] == ')')
k--;
else
k -= re[i];
if (k < 0) pos = false;
}
if (pos && k == 0) {
for (int i = 0; i < (int)h.size(); i++) cout << re[h[i]] << endl;
} else
cout << -1 << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int z;
z = 1;
while (z--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int lsone(int n) { return (n & -n); }
void mult(long long int a[25][25], long long int b[25][25],
long long int c[25][25], int m, int n, int p) {
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= p; j++) {
c[i][j] = 0;
for (int k = 1; k <= n; k++) {
c[i][j] += (a[i][k] * b[k][j]) % 1000000007;
c[i][j] %= 1000000007;
}
}
}
}
void mat_pow(long long int a[25][25], long long int c[25][25], int n,
long long int p) {
if (p == 0) {
for (int i = 1; i <= n; i++) c[i][i] = 1;
} else if (p == 1) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) c[i][j] = a[i][j];
}
} else {
long long int d[25][25];
mat_pow(a, d, n, p / 2);
if (p % 2) {
long long int e[25][25];
mult(d, d, e, n, n, n);
mult(e, a, c, n, n, n);
} else {
mult(d, d, c, n, n, n);
}
}
}
long long int pow1(long long int a, long long int b) {
if (b == 0)
return 1ll;
else if (b == 1)
return a;
else {
long long int x = pow1(a, b / 2);
x *= x;
x %= 1000000007;
if (b % 2) {
x *= a;
x %= 1000000007;
}
return x;
}
}
string s;
int numop, numcl, numh, diff[110000], maxim[110000];
vector<int> ans;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
cin >> s;
string t = "";
for (int i = 0; i < s.size(); i++) {
if (s[i] == '(')
numop++;
else if (s[i] == ')')
numcl++;
else
numh++;
}
int rem = numop - numcl, orgnh = numh;
if (rem < 0 or (rem < numh)) {
cout << -1 << "\n";
return 0;
}
for (int i = 0; i < s.size(); i++) {
if (s[i] != '#') {
t += s[i];
} else {
if (numh == 1) {
for (int j = 0; j < rem; j++) t += ")";
rem = 0;
} else {
t += ")";
rem--;
}
numh--;
}
}
int fl = 1, sum = 0;
for (int i = 0; i < t.size(); i++) {
if (t[i] == '(')
sum++;
else
sum--;
if (sum < 0) fl = 0;
}
if (!fl) {
cout << -1 << "\n";
return 0;
}
rem = numop - numcl;
numh = orgnh;
for (int i = 0; i < s.size(); i++) {
if (s[i] != '#') continue;
if (numh > 1) {
rem--;
cout << 1 << "\n";
} else {
cout << rem << "\n";
}
numh--;
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const double pi = acos(-1.0);
const int INF = 1000000007;
int n, m;
template <typename T>
inline void MustDie(T tmp) {
cout << tmp;
exit(0);
}
inline bool iscor(string s) {
int bal = 0;
for (int i = 0; i < (int)s.size(); ++i) {
s[i] == '(' ? ++bal : --bal;
if (bal < 0) return false;
}
return true;
}
int main() {
ios_base::sync_with_stdio(0);
string s;
cin >> s;
std::vector<int> c(max(')', max('(', '#')) + 1, 0);
for (int i = 0; i < (int)s.size(); ++i) ++c[s[i]];
if (c['('] <= c[')']) MustDie(-1);
if (c['('] - c[')'] < c['#']) MustDie(-1);
std::vector<int> a(c['#'], 1);
a[c['#'] - 1] += c['('] - c[')'] - c['#'];
string sans = "";
int j = 0;
for (int i = 0; i < (int)s.size(); ++i) {
if (s[i] != '#')
sans += s[i];
else {
for (int l = 0; l < (int)a[j]; ++l) sans += ')';
++j;
}
}
if (iscor(sans))
for (int i = 0; i < (int)c['#']; ++i) cout << a[i] << endl;
else
cout << -1;
exit(0);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
s += '.';
vector<int> result;
vector<int> braces;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '(') {
braces.push_back(i);
} else if (s[i] == ')') {
if (braces.empty()) {
cout << -1 << endl;
return 0;
}
s[braces.back()] = '.';
s[i] = '.';
braces.pop_back();
}
}
vector<char> t;
for (int i = 0; i < s.size(); i++) {
if (s[i] == ')') {
cout << -1 << endl;
return 0;
}
if (s[i] != '.') t.push_back(s[i]);
}
if (t.back() != '#') {
cout << -1 << endl;
return 0;
}
bool good = true;
int balance = 0;
for (int i = 0; i < t.size(); i++) {
if (t[i] == '(') {
balance++;
} else if (t[i] == '#') {
if (balance == 0) {
good = false;
break;
}
if (i != t.size() - 1) {
result.push_back(1);
balance--;
} else {
result.push_back(balance);
balance = 0;
}
}
}
if (balance > 0 || !good) {
cout << -1;
} else {
for (int i = 0; i < result.size(); i++) {
cout << result[i] << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
string s;
vector<int> p;
int xl() {
string ss = s;
if (s == "#") return -1;
int vv = 0;
int res = 0;
for (int i = s.size() - 1; i >= 0; i--) {
if (s[i] == '#') {
res = i;
break;
}
}
for (int i = 0; i < s.size(); i++) {
if (vv > 0) return -1;
if (s[i] == '#') {
if (i == res) continue;
if (vv == 0) return -1;
s[i] = ')';
vv++;
} else {
if (s[i] == ')')
vv++;
else
vv--;
}
}
if (vv >= 0) return -1;
vv = -vv;
string s1 = s.substr(0, res);
for (int i = 1; i <= vv; i++) s1 = s1 + ")";
s1 = s1 + s.substr(res + 1, s.size() - res);
int v = 0;
for (int i = 0; i < s1.size(); i++) {
if (v < 0) return -1;
if (s1[i] == ')')
v--;
else
v++;
}
if (v) return -1;
for (int i = 0; i < res; i++)
if (ss[i] == '#') cout << 1 << endl;
return vv;
}
int main() {
cin >> s;
cout << xl();
}
|
#include <bits/stdc++.h>
using namespace std;
void quit() {
cout << -1 << '\n';
exit(0);
}
int main() {
ostringstream oss;
string s;
cin >> s;
int v = 0, last = 0, lastv = 0;
if (s[0] == '#' || s[0] == ')' || s[s.length() - 1] == '(') quit();
for (last = s.length() - 1; last >= 0; last--)
if (s[last] == '#')
break;
else if (s[last] == '(')
lastv++;
else if (s[last] == ')')
lastv--;
if (lastv > 0) quit();
for (int i = 0; i < s.length(); i++) {
if (s[i] == ')')
v--;
else if (s[i] == '(')
v++;
else if (i == last) {
if (v + lastv <= 0)
quit();
else
cout << oss.str() << v + lastv << '\n';
return 0;
} else if (s[i] == '#') {
oss << "1\n";
v--;
}
if (v < 0) quit();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
string s;
int i, dep = 0, h, np = 1, last, n = 0, af = 0;
cin >> s;
for (i = 0; i < s.length(); i++) {
switch (s[i]) {
case '(': {
dep++;
break;
}
case ')': {
dep--;
break;
}
case '#': {
n++;
dep--;
h = dep;
break;
}
}
if (dep < 0) {
np = 0;
break;
}
}
i = s.length() - 1;
while (s[i] != '#') {
switch (s[i]) {
case '(': {
af++;
break;
}
case ')': {
af--;
break;
}
}
if (af > 0) {
np = 0;
break;
}
i--;
}
if (np != 0) {
{ last = h + af; }
}
if (np == 0)
cout << -1;
else {
for (i = 1; i <= n - 1; i++) cout << 1 << endl;
cout << last + 1;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int num_h = 0;
int diff = 0;
for (int i = 0; i < S.size(); ++i) {
if (S[i] == '(')
diff++;
else if (S[i] == ')')
diff--;
else
num_h++;
}
if (num_h > diff)
cout << -1 << endl;
else {
int n_diff = 0;
int n_h = num_h;
for (int i = 0; i < S.size(); ++i) {
if (S[i] == '(')
n_diff++;
else if (S[i] == ')')
n_diff--;
else {
n_diff--;
n_h--;
if (n_h == 0) n_diff -= diff - num_h;
}
if (n_diff < 0) {
cout << -1 << endl;
exit(0);
}
}
for (int i = 0; i < num_h; ++i) {
if (i == num_h - 1)
cout << diff - num_h + 1 << endl;
else
cout << 1 << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
string s;
int x, y, len, a, b;
int main() {
cin >> s;
len = s.length();
for (int i = 0; i < len; ++i) {
if (s[i] == '(')
++x;
else if (s[i] == ')')
--x;
else if (s[i] == '#')
--x, ++y;
if (x < 0) {
puts("-1");
exit(0);
}
}
for (int i = 0; i < len; ++i) {
if (s[i] == '#') {
++a;
if (a == y) b -= x;
--b;
}
if (s[i] == '(')
++b;
else if (s[i] == ')')
--b;
if (b < 0) {
puts("-1");
exit(0);
}
}
for (int i = 1; i < y; ++i) puts("1");
printf("%d", x + 1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[100005];
cin >> str;
int n = strlen(str);
int i = 0;
vector<char> v;
int pos;
int tot = 0;
int a = 0, b = 0, c = 0;
while (i < n) {
if (str[i] == '#') pos = i;
if (str[i] == '(') a++;
if (str[i] == ')') b++;
if (str[i] == '#') c++;
i++;
}
tot = a - b - c + 1;
if (a < b + c)
cout << "-1";
else {
i = 0;
while (i < n) {
if (i != pos) {
if (str[i] != '#')
v.push_back(str[i]);
else {
v.push_back(')');
b++;
}
} else {
for (int j = 1; j <= tot; j++) v.push_back(')');
}
i++;
}
int s = v.size();
int a = 0;
int b = 0;
int flag = 1;
for (int i = 0; i < s; i++) {
if (v[i] == '(')
a++;
else
b++;
if (b > a) {
flag = 0;
break;
}
}
if (flag == 0)
cout << "-1";
else {
for (int i = 0; i < n; i++) {
if (str[i] == '#') {
if (i != pos)
cout << "1\n";
else
cout << tot;
}
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
int cmp(const void* a, const void* b) { return *(int*)a - *(int*)b; }
int main() {
char a[100010];
int x, count = 0, z = 0, j, i, n, b[100010], l = 0;
scanf("%s", a);
n = strlen(a);
for (i = n - 1; a[i] != '#' && z >= 0 && i >= 0; i--)
if (a[i] == '(')
z--;
else
z++;
if (z < 0)
printf("-1\n");
else {
x = z;
z = 0;
l = 0;
for (j = 0; j < i; j++) {
if (a[j] == '(')
z++;
else if (a[j] == ')')
z--;
else {
b[l++] = z;
z = 0;
}
}
count = 0;
b[l++] = z - x;
for (i = 0; i < l; i++)
if (b[i] <= 0) {
count += 1 - b[i];
b[i] = 1;
}
for (i = 0; i < l; i++)
if (b[i] > 0) {
if (b[i] - 1 >= count) {
b[i] -= count;
count = 0;
} else {
count = count - b[i] + 1;
b[i] = 1;
}
}
if (count > 0)
printf("-1\n");
else {
x = 0;
z = 0;
qsort(b, l, sizeof(int), cmp);
for (i = 0; i < n && z <= 0; i++) {
if (a[i] == '(')
z--;
else if (a[i] == ')')
z++;
else
z += b[x++];
}
if (i == n) {
for (i = 0; i < l; i++) printf("%d\n", b[i]);
} else
printf("-1\n");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char arr[100001];
int sum[100001];
int tag = 1;
vector<int> l, ans;
int main() {
scanf(" %s", arr + 1);
int n = strlen(arr + 1);
for (int i = 1; i <= n; i++) {
if (arr[i] == '#') {
sum[i] = sum[i - 1];
l.push_back(i);
} else if (arr[i] == '(')
sum[i] = sum[i - 1] + 1;
else
sum[i] = sum[i - 1] - 1;
if (sum[i] < 0) tag = 0;
}
int balance = sum[n];
int count = 0;
if (balance < 0) tag = 0;
for (int i = 0; i < l.size() - 1; i++) {
int ind = l[i];
ans.push_back(1);
if (sum[ind] - count <= 0)
tag = 0;
else
count++;
}
int no = balance - count;
if (no <= 0) tag = 0;
if (sum[l[l.size() - 1]] - no < 0)
tag = 0;
else
ans.push_back(no);
count = 0;
for (int i = n; i >= 1; i--) {
if (arr[i] == '#') break;
if (arr[i] == '(')
count++;
else
count--;
if (count > 0) tag = 0;
}
if (tag) {
for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
} else
cout << "-1" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string s;
int sm, ff, ss, x;
int main() {
cin >> s;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '#') sm++;
if (s[i] == '(') ff++;
if (s[i] == ')') ss++;
if (ss + sm > ff) {
cout << -1;
return 0;
}
}
x = sm - 1;
if (ff <= ss || ff - ss - x <= 0 || s[s.size() - 1] == '(') {
cout << -1;
return 0;
}
int sq = 0, Sf = 0, Sj = 0;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '#') sq++;
if (s[i] == '(') Sf++;
if (s[i] == ')') Sj++;
if (sq == sm && s[i] == '#' && Sj + (ff - ss - x) > Sf) {
cout << -1;
return 0;
}
}
while (--sm) cout << 1 << "\n";
cout << ff - ss - x;
exit(0);
}
|
#include <bits/stdc++.h>
using namespace std;
char a[100007];
int main() {
scanf("%s", a);
int len = strlen(a);
int och = 0, yop = 0, sum = 0, resh = 0, x = 0;
for (int i = 0; i < len; i++) {
if (a[i] == '(') {
och++;
sum++;
x++;
} else if (a[i] == ')') {
yop++;
sum--;
x = max(x - 1, 0);
} else if (a[i] == '#') {
resh++;
sum--;
x = 0;
}
if (sum < 0) {
cout << "-1";
return 0;
}
}
if (och - yop < resh || x != 0) {
cout << "-1";
return 0;
}
for (int i = 0; i < resh - 1; i++) {
cout << "1" << endl;
}
cout << (och - yop) - resh + 1;
return 0;
}
|
#include <bits/stdc++.h>
template <class T>
T Max(T a, T b) {
return a < b ? b : a;
}
template <class T>
T Min(T a, T b) {
return a < b ? a : b;
}
template <class T>
T Max3(T a, T b, T c) {
return Max(Max(a, b), c);
}
template <class T>
T Min3(T a, T b, T c) {
return Min(Min(a, b), c);
}
template <class T>
void Swap(T& a, T& b) {
T temp;
temp = a;
a = b;
b = temp;
}
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
string s;
cin >> s;
int n = s.size();
int a[n + 1];
a[0] = 0;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '(')
a[i + 1] = a[i] + 1;
else if (s[i] == ')')
a[i + 1] = a[i] - 1;
else {
a[i + 1] = a[i];
cnt++;
}
}
for (int i = 1; i <= n; i++) {
if (a[i] < 0) {
cout << "-1";
return 0;
}
}
if (a[n] < cnt)
cout << "-1";
else {
int t = a[n];
int t1 = t, cnt1 = cnt;
string s1;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '#') {
if (cnt > 1) {
s1 += ')';
t--;
} else {
for (int i = 0; i < t; i++) s1 += ')';
}
cnt--;
} else {
s1 += s[i];
}
}
int n1 = s1.size();
int a1[n + 1];
a1[0] = 0;
for (int i = 0; i < n1; i++) {
if (s1[i] == '(')
a1[i + 1] = a1[i] + 1;
else if (s1[i] == ')')
a1[i + 1] = a1[i] - 1;
else
a1[i + 1] = a1[i];
}
for (int i = 1; i <= n1; i++) {
if (a1[i] < 0) {
cout << "-1";
return 0;
}
}
for (int i = 1; i < cnt1; i++) {
cout << "1\n";
t1--;
}
cout << t1;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int c = 0;
vector<int> v;
for (auto x : s) {
if (x == '(') c++;
if (x == ')') c--;
if (x == '#') {
v.push_back(1);
c--;
}
if (c < 0) {
cout << -1 << endl;
return 0;
}
}
v[v.size() - 1] = c + 1;
int i = 0;
int c2 = 0;
for (auto x : s) {
if (x == '(') c2++;
if (x == ')') c2--;
if (x == '#') {
c2 -= v[i++];
}
if (c2 < 0) {
cout << -1 << endl;
return 0;
}
}
if (c2 != 0) {
cout << -1 << endl;
return 0;
}
for (int i = 0; i < v.size(); i++) {
if (v[i] <= 0) {
cout << -1 << endl;
return 0;
}
}
for (int i = 0; i < v.size(); i++) {
cout << v[i] << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int replace1[1000006];
int idx[1000006];
int main() {
memset(replace1, 0, sizeof(replace1));
string str;
cin >> str;
int l = 0, r = 0, hash = 0;
for (int i = 0; i < str.size(); ++i) {
if (str[i] == '(') l++;
if (str[i] == ')') r++;
if (str[i] == '#') {
idx[hash] = i;
hash++;
}
if (l < r + hash) {
cout << "-1" << endl;
return 0;
}
}
int n = hash;
for (int i = 0; i < n - 1; ++i) replace1[idx[i]] = 1;
replace1[idx[hash - 1]] = l - r - n + 1;
l = 0, r = 0, hash = 0;
for (int i = 0; i < str.size(); ++i) {
if (str[i] == '(') l++;
if (str[i] == ')') r++;
if (str[i] == '#') {
hash += replace1[i];
}
if (l < r + hash) {
cout << "-1" << endl;
return 0;
}
}
for (int i = 0; i < n - 1; ++i) cout << 1 << endl;
cout << replace1[idx[n - 1]] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string s;
int n;
int i;
int main() {
cin >> s;
n = s.length();
int vt;
for (i = n - 1; i >= 0; i--)
if (s[i] == '#') {
vt = i;
break;
}
int hieu = 0, dem = 0;
for (i = 0; i < n; i++) {
if (s[i] == '#') dem++;
if (s[i] == '(')
hieu++;
else
hieu--;
if (hieu < 0) {
cout << -1;
return (0);
}
}
int hieucu = hieu;
hieu = 0;
for (i = 0; i < n; i++) {
if (s[i] == '(')
hieu++;
else
hieu--;
if (i == vt) hieu -= hieucu;
if (hieu < 0) {
cout << -1;
return (0);
}
}
for (i = 1; i < dem; i++) cout << 1 << endl;
cout << hieucu + 1 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int sum, tedad, bedehi;
string str;
int main() {
cin >> str;
for (int i = 0; i < ((int(str.size()))); i++) {
if (str[i] == ')') {
if (bedehi) bedehi--;
sum--;
}
if (str[i] == '(') {
bedehi++;
sum++;
}
if (str[i] == '#') {
bedehi = 0;
tedad++;
sum--;
}
if (sum < 0) {
cout << -1 << endl;
return 0;
}
}
if (bedehi) {
cout << -1 << endl;
return 0;
}
for (int i = 1; i < tedad; i++) {
cout << 1 << endl;
}
if (tedad == 0) {
cout << endl;
return 0;
}
cout << sum + 1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void remax(T& A, T B) {
if (A < B) A = B;
}
template <class T>
inline void remin(T& A, T B) {
if (A > B) A = B;
}
string ToString(long long num) {
string ret;
do {
ret += ((num % 10) + '0');
num /= 10;
} while (num);
reverse(ret.begin(), ret.end());
return ret;
}
long long ToNumber(string s) {
long long r = 0, p = 1;
for (int i = s.size() - 1; i >= 0; --i) r += (s[i] - '0') * p, p *= 10;
return r;
}
long long Gcd(long long a, long long b) {
if (!a) return b;
if (!b) return a;
while (a %= b ^= a ^= b ^= a)
;
return b;
}
long long Power(long long base, long long power) {
long long ret = 1;
while (power) {
if (power & 1) ret *= base;
power >>= 1;
base *= base;
}
return ret;
}
long long PowerMod(long long base, long long power, long long mod) {
if (!power) return 1;
if (power & 1) return (base * PowerMod(base, power - 1, mod)) % mod;
return PowerMod((base * base) % mod, power >> 1, mod);
}
int Log(long long num, long long base) {
int ret = 0;
while (num) {
++ret;
num /= base;
}
return ret;
}
int Count(long long mask) {
int ret = 0;
while (mask) {
if (mask & 1) ++ret;
mask >>= 1;
}
return ret;
}
inline void run() {
string s, t;
int arr[100000] = {};
int sz, a = 0, b = 0, c = 0, tmp = 0, last;
cin >> s;
sz = (int)s.size();
for (int i = 0; i < sz; ++i)
if (s[i] == '(')
++a;
else if (s[i] == ')')
++b;
else
++c;
if (c > a - b) {
puts("-1");
return;
}
a -= b;
for (int i = sz - 1; i >= 0; --i)
if (s[i] == '#') {
last = i;
break;
}
for (int i = 0; i < sz; ++i) {
if (s[i] == '(')
++tmp;
else if (s[i] == ')')
--tmp;
else if (i == last) {
arr[i] = a;
tmp -= a;
a = 0;
} else {
arr[i] = 1;
--a;
--tmp;
}
if (tmp < 0) {
puts("-1");
return;
}
}
for (int i = 0; i < sz; ++i)
if (arr[i]) printf("%d\n", arr[i]);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
run();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double pi = acos(-1.0);
const double eps = 1e-9;
string ans, second;
int n;
int p[100100], g[100100];
int d[100100];
vector<int> vans;
int main() {
cin >> second;
n = second.size();
for (int i = n - 1; i >= 0; i--) {
d[i] = d[i + 1];
p[i] = p[i + 1];
g[i] = g[i + 1];
if (second[i] == '#')
d[i]++;
else if (second[i] == '(')
p[i]++;
else
g[i]++;
}
int last = -1;
for (int i = 0; i < n; i++)
if (second[i] == '#') last = i;
int cur = p[0] - g[0];
if (last == -1 && cur != 0) {
cout << -1;
return 0;
}
if (cur < d[0]) {
cout << -1;
return 0;
}
for (int i = 0; i < n; i++) {
if (second[i] == '#') {
if (cur == 0) {
cout << -1;
return 0;
}
if (i == last) {
if (cur > i) {
cout << -1;
return 0;
}
for (int j = 1; j <= cur; j++) ans += ')';
vans.push_back(cur);
cur = 0;
continue;
}
vans.push_back(1);
cur--;
ans += ')';
} else {
ans += second[i];
}
}
int fq = 0, fp = 0;
for (int i = 0; i < ans.size(); i++) {
if (ans[i] == ')')
fq++;
else
fp++;
if (fq > fp) {
cout << -1;
return 0;
}
}
if (fq != fp) {
cout << -1;
return 0;
}
for (int i = 0; i < vans.size(); i++) cout << vans[i] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long g(long long a, long long b) {
if (b == 0)
return a;
else
return g(b, a % b);
}
char s[100010];
int main() {
int i, j, k, n, x, y, l, lst, op, cl, ans, op1, cl1, fl, hs;
x = y = op = cl = op1 = cl1 = fl = hs = 0;
cin >> s;
l = strlen(s);
for (i = 0; i < l; i++) {
if (s[i] == '#') hs++;
}
for (i = l - 1; i >= 0; i--) {
if (s[i] == '#') {
lst = i;
break;
}
}
for (i = 0; i < lst; i++) {
if (s[i] == '(')
op++;
else {
cl++;
if (cl > op) {
fl = 1;
break;
}
}
}
for (i = lst + 1; i < l; i++) {
if (s[i] == '(')
op1++;
else
cl1++;
}
ans = op + op1 - cl - cl1;
if (ans <= 0 || ans + cl > op) fl = 1;
cl += ans;
for (i = lst + 1; i < l; i++) {
if (s[i] == '(')
op++;
else {
cl++;
if (cl > op) {
fl = 1;
break;
}
}
}
if (fl) {
cout << "-1\n";
} else {
for (i = 1; i < hs; i++) cout << "1\n";
cout << ans << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e15;
const long long int mod = 1000000007;
int main() {
std::ios::sync_with_stdio(false);
string s;
vector<int> v;
cin >> s;
int len = s.size();
int l = 0, r = 0;
for (int i = 0; i < len; i++) {
if (s[i] == '(') l++;
if (s[i] == ')') r++;
if (s[i] == '#') v.push_back(i);
}
if (r >= l) {
cout << "-1\n";
return 0;
}
for (int i = 0; i < v.size() - 1; i++) {
s[v[i]] = ')';
}
int faltan = l - r - v.size() + 1;
if (faltan <= 0) {
cout << "-1\n";
return 0;
}
s[v.back()] = 'X';
l = 0, r = 0;
bool yes = true;
for (int i = 0; i < len; i++) {
if (s[i] == '(')
l++;
else if (s[i] == ')')
r++;
else {
r += faltan;
}
if (r > l) {
yes = false;
break;
}
}
if (yes and r == l) {
for (int i = 0; i < v.size() - 1; i++) cout << 1 << "\n";
cout << faltan << "\n";
} else {
cout << "-1\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
const int INF = 1000000;
char s[N];
int ans[N];
int main() {
scanf("%s", s);
int n = strlen(s);
int nsh = 0;
for (int i = 0; i < n; i++)
if (s[i] == '#') ans[nsh++] = 1;
int cur = 0, idx = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '(')
cur++;
else if (s[i] == ')')
cur--;
else {
if (idx == nsh - 1) {
int need = cur;
i++;
while (i < n) {
if (s[i] == ')')
need--;
else if (s[i] == '(')
need++;
i++;
}
ans[idx] = max(1, need);
break;
} else
cur--;
idx++;
}
}
cur = 0, idx = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '(')
cur++;
else if (s[i] == ')')
cur--;
else
cur -= ans[idx++];
if (cur < 0) {
printf("-1\n");
return 0;
}
}
for (int i = 0; i < nsh; i++) printf("%d\n", ans[i]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool check(vector<int> &V, string &s) {
int it = 0;
int left = 0, right = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '(')
left++;
else if (s[i] == ')')
right++;
else
right += V[it++];
if (right > left) return 0;
}
return 1;
}
int main() {
ios_base::sync_with_stdio(0);
string s;
cin >> s;
int left = 0, right = 0, hashes = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '(')
left++;
else if (s[i] == ')')
right++;
else
hashes++;
}
if (hashes + right > left) {
cout << -1;
return 0;
}
vector<int> V;
for (int i = 0; i < hashes - 1; i++) V.push_back(1);
V.push_back(left - (right + hashes - 1));
if (!check(V, s)) {
cout << -1;
return 0;
}
for (int i = 0; i < V.size(); i++) cout << V[i] << endl;
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int a[100100];
int main() {
string s;
cin >> s;
int cur = 0;
int pos = -1;
for (int _n((s.size()) - 1), i(0); i <= _n; ++i) {
if (s[i] == '(')
cur++, a[i]++;
else if (s[i] == ')')
cur--, a[i]--;
else {
pos = i;
cur--;
a[i]--;
}
if (cur < 0) {
cout << -1 << endl;
return 0;
}
}
if (pos + 1) a[pos] -= cur;
int balance = 0;
for (int _n((s.size()) - 1), i(0); i <= _n; ++i) {
balance += a[i];
if (balance < 0) {
cout << -1 << endl;
return 0;
}
}
if (balance) {
cout << -1 << endl;
return 0;
}
for (int _n((s.size()) - 1), i(0); i <= _n; ++i)
if (s[i] == '#') cout << -a[i] << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int k1 = 0, k2 = 0;
string s;
int main() {
getline(cin, s);
int l = s.size();
if (s[l - 1] == '(') {
cout << "-1\n";
return 0;
}
for (int i = 0; i < l; ++i) {
if (s[i] == '(')
++k1;
else if (s[i] == ')')
--k1;
else if (s[i] == '#')
++k2;
if (k2 > k1) {
cout << "-1\n";
return 0;
}
}
int kk = 0;
int i = l - 1;
while (s[i] != '#') {
if (s[i] == ')')
++kk;
else if (s[i] == '(')
--kk;
if (kk < 0) {
cout << "-1\n";
return 0;
}
--i;
}
if (k2 > k1)
cout << "-1\n";
else {
for (int i = 1; i < k2; ++i) cout << "1\n";
cout << k1 - k2 + 1 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int n, poz, cnt, ndiez, l, r, l0, r0;
string s;
int32_t main() {
ios_base ::sync_with_stdio(0);
cin.tie();
cout.tie();
cin >> s;
n = s.size();
for (int i = n - 1; i >= 0; i--) {
if (s[i] == '#') {
poz = i;
break;
}
}
for (int i = 0; i < n; i++) {
if (i < poz) {
if (s[i] == '(')
l++;
else
r++;
if (s[i] == '#') ndiez++;
if (l - r < 0) {
cout << -1;
return 0;
}
}
if (i == poz) {
l0 = l;
r0 = r;
}
if (i > poz) {
if (s[i] == '(')
l++;
else
r++;
}
}
if (l - r <= 0) {
cout << -1;
return 0;
}
cnt = l - r;
l = l0;
r = r0 + cnt;
if (l - r < 0) {
cout << -1;
return 0;
}
for (int i = poz + 1; i < n; i++) {
if (s[i] == '(')
l++;
else
r++;
if (l - r < 0) {
cout << -1;
return 0;
}
}
for (int i = 1; i <= ndiez; i++) cout << 1 << '\n';
cout << cnt;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void ruint(T& a) {
while ((a = getchar_unlocked() - '0') < 0)
;
for (register char c; (c = getchar_unlocked() - '0') >= 0;)
a = (a << 3) + (a << 1) + c;
}
struct Reader {
template <class T>
Reader& operator,(T& v) {
cin >> v;
return *this;
}
} RD;
struct ReaderU {
template <class T>
ReaderU& operator,(T& v) {
ruint(v);
return *this;
}
} RU;
struct Debugger {
template <class T>
Debugger& operator,(const T& v) {
cout << " " << v << flush;
return *this;
}
} DB;
struct classcomp {
template <class T>
bool operator()(const T& a, const T& b) const {
return a > b;
}
};
template <class T>
void Dbrng(T lo, T hi, string note = "", int w = 0) {
if (0) {
cout << "Debug[ ";
if (!note.empty()) cout << setw(3) << note << " : ";
for (; lo != hi; ++lo) cout << setw(w) << *lo << " ";
cout << "]" << endl;
}
}
const int INF = 0x3F3F3F3F;
string s;
int cnt, last, ans[100005];
int main() {
if (0)
({
if (*"a.in") freopen("a.in", "r", stdin);
if (*"") freopen("", "w", stdout);
});
({
ios_base::sync_with_stdio(false);
cin.tie(0);
});
cin >> s;
for (int i = 0, _i = (s.size()); i < _i; ++i) {
if (s[i] == '(')
cnt++;
else if (s[i] == ')')
cnt--;
else {
ans[i] = 1;
cnt--;
last = i;
}
}
if (cnt > 0) ans[last] += cnt;
cnt = 0;
for (int i = 0, _i = (s.size()); i < _i; ++i) {
if (s[i] == '(')
cnt++;
else if (s[i] == ')')
cnt--;
else
cnt -= ans[i];
if (cnt < 0) return !printf("-1\n");
}
if (cnt != 0) return !printf("-1\n");
for (int i = 0, _i = (s.size()); i < _i; ++i)
if (s[i] == '#') printf("%d\n", ans[i]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
int last;
int open = 0, close = 0, other = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '(') open++;
if (s[i] == ')') close++;
if (s[i] == '#') other++, last = i;
}
if (close + other > open) {
puts("-1");
return 0;
}
int ultimo = open - close - (other - 1);
open = close = 0;
bool valid = true;
for (int i = 0; i < n; ++i) {
if (s[i] == '(')
open++;
else if (s[i] == ')')
close++;
else {
if (i == last) {
last = ultimo;
close += ultimo;
} else {
close++;
}
}
if (close > open) {
valid = false;
}
}
if (valid) {
for (int i = 0; i < other - 1; ++i) printf("1\n");
printf("%d\n", last);
} else {
cout << -1 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int MAX = 1000000009;
int comparedec(int a, int b) {
if (a > b) {
return 1;
}
return 0;
}
int compareinc(int a, int b) {
if (a < b) {
return 1;
}
return 0;
}
int main() {
int i, j;
string s;
cin >> s;
stack<char> st;
stack<int> st1;
vector<int> ans;
int last = -1;
int fl = 1;
for (i = 0; i < s.length(); i++) {
if (s[i] == '(') {
st.push(s[i]);
st1.push(i);
} else if (s[i] == ')') {
if (!st.empty() && st.top() == '(') {
st.pop();
st1.pop();
} else {
st.push(')');
fl = 0;
}
} else if (s[i] == '#') {
if (!st.empty() && st.top() == '(') {
st.pop();
st1.pop();
ans.push_back(1);
} else {
st.push('#');
fl = 0;
}
last = i;
}
}
int k = st.size();
if (!st.empty() && !st1.empty()) {
if (st1.top() < last) {
ans[ans.size() - 1] += st.size();
} else {
fl = 0;
}
}
if (fl == 0) {
cout << "-1" << endl;
} else {
for (i = 0; i < ans.size(); i++) {
cout << ans[i] << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_SIZE = 100500;
string s;
int d[MAX_SIZE];
int cnt[MAX_SIZE];
int c1, c2;
void ex() {
cout << -1 << endl;
exit(0);
}
inline void solve() {
cin >> s;
int n = (int)s.size();
if (s[0] != '(') {
ex();
}
d[0] = 1;
c1 = 1;
for (int i = 1; i < n; ++i) {
if (s[i] == '(') {
d[i] = d[i - 1] + 1;
++c1;
} else {
d[i] = d[i - 1] - 1;
++c2;
}
if (d[i] < 0) {
ex();
}
if (s[i] == '#') {
cnt[i] = 1;
}
}
if (c1 < c2) {
ex();
}
for (int i = n - 1; i >= 0; --i) {
if (s[i] == '#') {
d[i] -= c1 - c2;
if (d[i] < 0) {
ex();
}
cnt[i] += c1 - c2;
for (int j = i + 1; j < n; ++j) {
if (s[j] == '(') {
d[j] = d[j - 1] + 1;
} else {
d[j] = d[j - 1] - 1;
}
if (d[j] < 0) {
ex();
}
}
break;
}
}
for (int i = 0; i < n; ++i) {
if (cnt[i]) {
cout << cnt[i] << "\n";
}
}
}
int main() {
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int counter = 0, count = 1, c = 0, dif = 0;
cin >> s;
int n = s.length();
for (int i = 0; i < n; i++) {
if (s[i] == '(') counter++;
if (s[i] == ')') counter--;
if (s[i] == '#') c++;
if (counter < 0) {
cout << "-1";
return 0;
}
}
if (counter < c) {
cout << "-1";
return 0;
}
if (c == 0 && counter != 0) {
cout << "-1";
return 0;
}
dif = counter;
counter = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '(') counter++;
if (s[i] == ')') counter--;
if (s[i] == '#' && count != c) {
counter--;
count++;
} else if (s[i] == '#' && count == c)
counter -= dif - c + 1;
if (counter < 0) {
cout << "-1";
return 0;
}
}
for (int i = 0; i < c - 1; i++) {
cout << 1 << endl;
}
if (c > 0) cout << dif - c + 1;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[1000005];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int cnt = 0, idx = 0, last = 0, val = 0, cnt1 = 0;
for (int i = 0; i < s.size();) {
if (cnt < 0) break;
if (s[i] == '(') {
cnt++;
i++;
continue;
}
if (s[i] == ')') {
cnt--;
i++;
continue;
}
if (s[i] == '#') {
i++;
val = cnt;
last = i;
cnt--;
a[idx++] = 1;
}
}
if (cnt < 0) {
cout << "-1";
return 0;
}
int x = val;
for (int i = last; i < s.size(); i++) {
if (s[i] == ')')
val--;
else
val++;
}
while (last < s.size() && s[last] == ')') last++, cnt1++;
if (val + cnt1 > x) {
cout << "-1";
return 0;
}
a[idx - 1] = val;
for (int i = 0; i < idx; i++) cout << a[i] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MAX = -1000000000000000000;
const long long MIN = 1000000000000000000;
const long long inf = 1000000000;
const long long KOK = 100000;
const long long LOG = 30;
const long long li = 500005;
const long long mod = 1000000007;
int n, m, b[li], a[li], k, flag, t, yes, say, ind, cev1, mn, cev2;
int cev;
string s;
vector<int> v;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> s;
for (int i = 0; i < (int)s.size(); i++) {
if (s[i] == '#') {
say++;
ind = i;
}
}
for (int i = 0; i < (int)s.size(); i++) {
if (ind == i) {
if (cev <= 0) {
printf("-1\n");
return 0;
}
a[1] = cev;
cev = 0;
continue;
}
if (i > ind) {
if (s[i] == '(')
cev++;
else if (s[i] == ')' && cev > 0) {
cev--;
} else if (s[i] == ')' && a[1] > 1) {
a[1]--;
} else {
printf("-1\n");
return 0;
}
} else {
if (s[i] == '(')
cev++;
else
cev--;
if (cev < 0) {
printf("-1\n");
return 0;
}
}
}
if (cev > 0) {
printf("-1\n");
return 0;
}
for (int i = 1; i < say; i++) printf("1\n");
printf("%d\n", a[1]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
string s;
vector<int> vc;
int n, a, b, cu = 0, cut = 0;
cin >> s;
for (int i = 0; i < s.length(); ++i) {
if (s[i] == '(') {
++cu;
} else if (s[i] == ')') {
--cu;
} else {
--cu;
vc.push_back(1);
cut = cu;
}
if (cu < 0) {
cout << -1 << endl;
return 0;
}
cut = min(cut, cu);
}
if (cu == 0) {
for (int i = 0; i < vc.size(); ++i) cout << vc[i] << '\n';
return 0;
}
if (cut < cu || (cu != 0 && vc.size() == 0)) {
cout << -1 << endl;
return 0;
}
vc[vc.size() - 1] += cu;
for (int i = 0; i < vc.size(); ++i) cout << vc[i] << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
string s;
cin >> s;
int cont = 0;
vector<int> ans;
bool ok = true;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '(') ++cont;
if (s[i] == ')') --cont;
if (s[i] == '#') {
ans.push_back(1);
--cont;
}
}
if (cont < 0)
ok = false;
else
ans[int(ans.size()) - 1] += cont;
int pos = 0;
cont = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '(') ++cont;
if (s[i] == ')') --cont;
if (s[i] == '#') {
cont -= ans[pos++];
}
if (cont < 0) ok = false;
}
if (ok) {
for (int i = 0; i < ans.size(); i++) {
cout << ans[i] << endl;
}
} else
cout << -1 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5;
char s[Maxn + 5];
int a[Maxn + 5];
int main() {
scanf("%s", s);
int pos, cntll = 0, cntrr = 0;
int len = strlen(s);
for (int i = 0; i <= len - 1; i++)
if (s[i] == '#') pos = i;
int cntl = 0, cntr = 0, ans = 0, tot = 0;
for (int i = 0; i <= pos; i++) {
if (s[i] == '(') cntl++;
if (s[i] == ')') cntr++;
if (s[i] == '#') {
if (cntl <= cntr) {
printf("-1\n");
return 0;
} else {
a[++tot] = 1;
cntr++;
}
}
}
for (int i = pos; i <= len - 1; i++) {
if (s[i] == '(') cntl++;
if (s[i] == ')') cntr++;
}
if (cntr > cntl) {
printf("-1\n");
return 0;
} else {
a[tot] = cntl - cntr + 1;
if (a[tot] <= 0) {
printf("-1\n");
return 0;
}
int cntll = 0, cntrr = 0, nie = 1;
for (int i = 0; i <= len - 1; i++) {
if (s[i] == '(')
cntll++;
else {
if (s[i] == ')') cntrr++;
if (s[i] == '#') cntrr += a[nie], nie++;
}
if (cntrr > cntll) {
printf("-1\n");
return 0;
}
}
}
for (int i = 1; i <= tot; i++) printf("%d\n", a[i]);
}
|
#include <bits/stdc++.h>
using namespace std;
string s;
int a, b, f;
int main() {
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '(')
a++;
else
a--;
if (a < 0) {
cout << -1 << endl;
return 0;
}
if (s[i] == '#') f++;
}
for (int i = s.size() - 1; i >= 0; i--) {
if (s[i] == '#') break;
if (s[i] == ')')
b++;
else
b--;
if (b < 0) {
cout << -1 << endl;
return 0;
}
}
if (f == 0 && a != 0) {
cout << -1 << endl;
return 0;
}
for (int i = 1; i < f; i++) cout << 1 << " ";
cout << a + 1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
char a[maxn];
int N, cnt[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> (a + 1);
N = strlen(a + 1);
int last_hash = 0;
vector<int> ans;
for (int i = 1; i <= N; ++i)
if (a[i] == '#') last_hash = i;
for (int i = 1; i <= N; ++i) {
cnt[i] += cnt[i - 1];
if (a[i] == '(') ++cnt[i];
if (a[i] == ')') --cnt[i];
if (a[i] == '#') --cnt[i];
if (cnt[i] < 0) {
cout << -1 << endl;
exit(0);
}
if (a[i] == '#') {
if (i < last_hash) ans.push_back(1);
}
}
ans.push_back(cnt[N] + 1);
int pos = 0;
for (int i = 1; i <= N; ++i) {
cnt[i] = 0;
cnt[i] += cnt[i - 1];
if (a[i] == '(') ++cnt[i];
if (a[i] == ')') --cnt[i];
if (a[i] == '#') {
cnt[i] -= ans[pos];
++pos;
}
if (cnt[i] < 0) {
cout << -1 << endl;
exit(0);
}
}
if (cnt[N] > 0) {
cout << -1 << endl;
exit(0);
}
for (int i : ans) cout << i << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
vector<int> sharp;
queue<int> cl;
int open = 0, close = 0, start = 0;
string s;
cin >> s;
int lastsharp = -1;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '#') lastsharp = i;
}
if (lastsharp == -1) {
cout << "-1";
return 0;
}
for (int i = 0; i < s.size(); i++) {
if (s[i] == '(') {
open++;
if (i > lastsharp) start++;
} else if (s[i] == ')') {
close++;
if (i > lastsharp) {
start--;
if (start < 0) start = 0;
}
} else if (i != lastsharp) {
close++;
sharp.push_back(1);
}
if (close > open) {
cout << -1;
return 0;
}
}
if (open - close == 0) {
cout << -1;
return 0;
}
if (start > 0) {
cout << -1;
return 0;
}
sharp.push_back(open - close);
for (int i = 0; i < sharp.size(); i++) cout << sharp[i] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
cin >> s;
n = s.length();
int cnt = 0;
bool flag = true;
int last = -1;
for (int i = 0; i < n; ++i) {
if (s[i] == '(')
++cnt;
else
--cnt;
if (cnt < 0) {
flag = false;
break;
}
if (s[i] == '#') last = i;
}
if (!flag)
cout << -1 << endl;
else {
int t = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '(')
++t;
else if (s[i] == ')')
--t;
else {
if (i != last)
--t;
else
t -= cnt + 1;
}
if (t < 0) {
flag = false;
break;
}
}
if (!flag)
cout << -1 << endl;
else {
for (int i = 0; i < n; ++i)
if (s[i] == '#') {
if (i != last)
cout << 1 << endl;
else
cout << cnt + 1 << endl;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
string s;
cin >> s;
vector<int> pos;
int l = s.length();
for (int i = 0; i < l; ++i) {
if (s[i] == '#') {
s[i] = ')';
pos.push_back(i);
}
}
int n = pos.size();
vector<int> ans(n, 1);
int bal = 0;
vector<int> b(l);
for (int i = 0; i < l; ++i) {
bal += (s[i] == '(') ? 1 : -1;
if (bal < 0) {
cout << -1;
return 0;
}
b[i] = bal;
}
vector<int> min_b(l);
min_b[l - 1] = b[l - 1];
for (int i = l - 2; i >= 0; --i) min_b[i] = min(b[i], min_b[i + 1]);
int need = bal;
int all = 0;
bal = 0;
int cur = 0;
for (int i = 0; i < l; ++i) {
bal += (s[i] == '(') ? 1 : -1;
if (cur < n && i == pos[cur]) {
int add = min(min_b[i] - all, need);
ans[cur] += add;
need -= add;
bal -= add;
all += add;
++cur;
}
}
if (bal > 0) {
cout << -1;
return 0;
}
for (int i = 0; i < n; ++i) cout << ans[i] << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005], c[100005];
int main() {
char s[100005];
int flag = 0, i, j, hash = 0;
scanf("%s", s);
for (i = 0; s[i]; i++) {
if (s[i] == '(')
break;
else {
printf("-1");
return 0;
}
}
a[0] = 1;
for (i = 1; s[i]; i++) {
if (s[i] == '#') {
hash++;
b[i] = hash;
a[i] = a[i - 1];
} else {
if (s[i] == '(')
a[i] = a[i - 1] + 1;
else
a[i] = a[i - 1] - 1;
}
}
for (j = i - 1; j >= 0; j--) {
if (s[j] == '(') {
printf("-1");
return 0;
} else
break;
}
int kk;
int lenght = i - 1, l;
int q = 0;
for (kk = lenght;; kk--) {
if (s[kk] == ')')
q++;
else if (s[kk] == '(')
q--;
else
break;
}
for (j = lenght; j >= 0; j--) {
if (s[j] == '#') {
l = a[j] - (b[j] - 1) - q;
c[j] = l, flag = 1;
for (i = j - 1; i >= 0; i--) {
if (s[i] == '#') c[i] = 1, flag = 1;
}
goto in;
}
}
in:;
flag = 0;
int k2;
stack<int> s1;
for (i = 0; s[i]; i++) {
if (s[i] == '(')
s1.push(1);
else if (s[i] == ')') {
if (s1.empty()) {
printf("-1");
return 0;
} else
s1.pop();
} else if (s[i] == '#') {
k2 = c[i];
while (k2--) {
if (s1.empty()) {
printf("-1");
return 0;
} else
s1.pop();
}
}
}
if (s1.empty()) {
for (i = 1; i <= lenght; i++) {
if (c[i] > 0) {
flag = 1;
printf("%d\n", c[i]);
}
}
}
if (flag != 1) printf("-1");
}
|
#include <bits/stdc++.h>
using namespace std;
char s[100100];
int len, p, tot, stop;
int main() {
scanf("%s", s);
len = strlen(s);
for (int i = len - 1; i >= 0; i--) {
if (s[i] == ')') p++;
if (s[i] == '(') {
p--;
if (p < 0) {
printf("-1\n");
return 0;
}
}
if (s[i] == '#') {
stop = i;
break;
}
}
p = 0;
for (int i = 0; i < len; i++) {
if (s[i] == '(') p++;
if (s[i] == ')' || s[i] == '#') {
p--;
tot += (s[i] == '#');
if (p < 0) {
printf("-1\n");
return 0;
}
}
}
for (int i = 1; i < tot; i++) printf("1\n");
printf("%d\n", p + 1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10005;
int main() {
string s;
while (cin >> s) {
bool ok = true;
int cnt = 0, last = 0;
int cnt2 = 0, cnt1 = 0;
for (int i = 0; i < (int)s.size(); ++i) {
if (s[i] == '(') cnt1++;
}
for (int i = 0; i < (int)s.size(); ++i) {
if (s[i] == ')') cnt1--;
if (s[i] == '#') cnt2++;
}
for (int i = (int)s.size() - 1; i >= 0; i--)
if (s[i] == '#') {
last = i;
break;
}
for (int i = 0; i < (int)s.size(); ++i) {
if (i == last)
cnt -= max(1, (cnt1 - (cnt2 - 1)));
else if (s[i] == '(')
cnt++;
else
cnt--;
if (cnt < 0) ok = false;
}
if (ok) {
for (int i = 0; i < cnt2 - 1; ++i) {
cout << "1" << endl;
}
if (cnt2 > 0) cout << (cnt1 - (cnt2 - 1)) << endl;
} else {
cout << "-1" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int sz = 2e5 + 100;
int main() {
int x, i, j, k, l, m, p, q;
string str;
cin >> str;
bool bl = true;
int len = str.length();
stack<char> st;
int last = -1, ct = 0;
int ans[len];
for (i = len - 1; i >= 0; i--) {
if (str[i] == ')')
st.push(')');
else if (str[i] == '#')
st.push(')'), last = 0, ans[ct++] = 1;
else {
if (st.size() == 0 && last == -1)
bl = false;
else {
if (st.size() > 0)
st.pop();
else
++ans[last];
}
}
}
if (st.size() > 0) bl = false;
if (!bl)
cout << "-1\n";
else {
for (i = ct - 1; i >= 0; i--) cout << ans[i] << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
string s;
int a, b, c, d, fol[100005], nr[100005], lst;
vector<int> rez;
int main() {
cin >> s;
stack<int> st;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '(') {
++a;
st.push(i);
} else {
++b;
if (!st.size()) {
cout << "-1";
return 0;
}
int tp = st.top();
fol[tp] = fol[i] = 1;
st.pop();
++nr[i];
if (s[i] == '#') {
rez.push_back(1);
lst = i;
}
}
}
nr[lst] += st.size();
rez[rez.size() - 1] += st.size();
for (; st.size(); st.pop())
;
for (int i = 0; i < s.size(); ++i)
if (s[i] == '(')
st.push(i);
else
for (int j = 1; j <= nr[i]; ++j) {
if (!st.size()) {
cout << "-1";
return 0;
}
st.pop();
}
for (int i = 0; i < rez.size(); ++i) cout << rez[i] << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin >> s;
long long bal = 0, n = s.size();
vector<long long> ans;
vector<long long> st;
vector<long long> vis(n, 0);
long long count = 0;
for (long long i = 0; i < s.size(); i++) {
if (s[i] == '#') {
if (bal <= count) {
cout << -1;
return 0;
}
count++;
} else if (s[i] == '(') {
bal++;
st.push_back(i);
} else {
if (st.size() == 0) {
cout << -1;
return 0;
}
st.pop_back();
bal--;
}
}
while (st.size() > 0) {
vis[st.back()] = 1;
st.pop_back();
}
string str = "";
long long a = 0, b = 0;
for (long long i = 0; i < n; i++) {
if (s[i] == '#') {
str += s[i];
a++;
} else if (s[i] == '(' and vis[i] == 1) {
str += s[i];
b++;
}
}
n = str.size();
if (a > b or str[n - 1] == '(') {
cout << -1;
return 0;
}
for (long long i = 1; i < a; i++) cout << 1 << '\n';
cout << b - (a - 1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
char s[MAX_N + 4];
int cs[MAX_N];
int main() {
scanf("%s", s);
int n = strlen(s);
int p = 0, m = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '(')
p++;
else {
p--;
if (p < 0) {
puts("-1");
return 0;
}
if (s[i] == '#') cs[m++] = 1;
}
}
cs[m - 1] += p;
for (int i = 0, j = 0, p = 0; i < n; i++) {
if (s[i] == '(')
p++;
else {
p -= (s[i] == '#') ? cs[j++] : 1;
if (p < 0) {
puts("-1");
return 0;
}
}
}
for (int i = 0; i < m; i++) printf("%d\n", cs[i]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
while (b > 0) {
a %= b;
swap(a, b);
}
return a;
}
template <class _T>
inline _T sqr(const _T& first) {
return first * first;
}
template <class _T>
inline string tostr(const _T& a) {
ostringstream os("");
os << a;
return os.str();
}
const long double PI = 3.1415926535897932384626433832795L;
const double EPS = 1e-9;
char TEMPORARY_CHAR;
const int INF = 1e9;
inline void input(int& a) {
a = 0;
while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') &&
(TEMPORARY_CHAR != '-')) {
}
char neg = 0;
if (TEMPORARY_CHAR == '-') {
neg = 1;
TEMPORARY_CHAR = getchar();
}
while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') {
a = 10 * a + TEMPORARY_CHAR - '0';
TEMPORARY_CHAR = getchar();
}
if (neg) a = -a;
}
inline void out(long long a) {
if (!a) putchar('0');
if (a < 0) {
putchar('-');
a = -a;
}
char s[20];
int i;
for (i = 0; a; ++i) {
s[i] = '0' + a % 10;
a /= 10;
}
for (int j = (i)-1; j >= 0; j--) putchar(s[j]);
}
inline int nxt() {
int(ret);
input((ret));
;
return ret;
}
int main() {
string s;
cin >> s;
int cnt = 0;
int was[s.length()];
memset((was), 0, sizeof(was));
vector<int> ans;
int pos = -1;
for (char c : s) {
pos++;
if (c == ')') {
if (cnt == 0) {
while (!ans.empty() && was[ans.back()] == 1) {
ans.pop_back();
}
if (!ans.empty()) {
was[ans.back()]--;
continue;
} else {
puts("-1");
return 0;
}
}
--cnt;
continue;
}
if (c == '(') {
++cnt;
continue;
}
if (cnt == 0) {
while (!ans.empty() && was[ans.back()] == 1) {
ans.pop_back();
}
if (!ans.empty()) {
was[ans.back()]--;
++cnt;
} else {
puts("-1");
return 0;
}
}
if (cnt == 0) {
puts("-1");
return 0;
}
ans.push_back(pos);
was[pos] = cnt;
cnt = 0;
}
while (cnt) {
while (!ans.empty() && was[ans.back()] == 1) {
ans.pop_back();
}
if (ans.empty()) {
puts("-1");
return 0;
}
was[ans.back()]--;
}
for (int i = 0; i < (int)s.length(); ++i) {
if (was[i]) {
cout << was[i] << "\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int N;
string s;
stack<int> S;
int main(void) {
cin >> s;
N = s.size();
int p;
for (int i = 0; i < N; i++) {
if (s[i] == '(')
S.push(i);
else {
if (S.size() == 0) {
printf("-1");
return 0;
}
S.pop();
}
if (s[i] == '#') p = i;
}
for (int i = N - 1; i >= 0; i--) {
if (s[i] == ')' || s[i] == '#')
break;
else {
printf("-1");
return 0;
}
}
if (!S.empty() && S.top() > p) {
printf("-1\n");
return 0;
}
int otvorene = 0;
for (int i = 0; i < N; i++) {
if (s[i] == '(') otvorene++;
if (s[i] == ')') otvorene--;
if (s[i] == '#' && i != p) printf("1\n");
if (s[i] == '#') otvorene--;
}
printf("%d\n", otvorene + 1);
return 0;
}
|
#include <bits/stdc++.h>
int main(void) {
char s[100002];
scanf("%s", s);
int len = strlen(s);
int pl[100002];
int i, cnt = 0, last;
for (i = 0; i < len; i++) {
if (s[i] == '(')
pl[i] = 1, cnt++;
else if (s[i] == ')')
pl[i] = -1, cnt--;
else
pl[i] = -1, cnt--, last = i;
}
pl[last] = -cnt - 1;
bool ok = ((-cnt - 1) < 0);
int tot = 0;
for (i = 0; i < len; i++) {
tot += pl[i];
if (tot < 0) ok = false;
}
if (!ok)
printf("-1\n");
else {
for (i = 0; i < len; i++) {
if (s[i] == '#') printf("%d\n", -pl[i]);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-10;
string ipstr, opstr;
int a, b, c;
vector<int> solution;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> ipstr;
for (int i = 0, _a = (ipstr.size()); i < _a; i++) {
if (ipstr[i] == '(')
++a, ++c;
else {
--a;
if (c > 0) --c;
if (a < 0) {
cout << -1 << endl;
return 0;
}
if (ipstr[i] == '#') {
c = 0;
++b;
}
}
}
if (c > 0) {
cout << -1 << endl;
return 0;
}
for (int i = (1), _b = (b - 1); i <= _b; i++) cout << 1 << endl;
cout << a + 1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve(char* s) {
bool seen = false;
int output = 0;
for (int i = strlen(s) - 1; i >= 0; i--) {
if (s[i] == '#' && !seen) {
seen = true;
continue;
} else {
if (s[i] == '#') {
output++;
s[i] = ')';
}
}
}
int counter = 0;
int ans = -1;
int pos = 0;
seen = false;
for (int i = 0; i < strlen(s); i++) {
if (s[i] == '(') {
counter++;
} else if (s[i] == ')') {
counter--;
} else if (s[i] == '#') {
ans = counter;
pos = i;
break;
}
if (counter < 0) {
break;
}
}
if (counter <= 0) {
cout << -1 << endl;
return;
}
counter = 0;
for (int i = pos + 1; i <= strlen(s); i++) {
if (s[i] == '(') counter++;
if (s[i] == ')') counter--;
}
if (counter > 0) {
cout << -1 << endl;
return;
}
ans += counter;
counter = 0;
for (int i = 0; i < strlen(s); i++) {
if (s[i] == '(') counter++;
if (s[i] == ')') counter--;
if (s[i] == '#') counter -= ans;
if (counter < 0) {
ans = -100;
break;
}
}
if (ans <= 0 || counter < 0) {
cout << -1 << endl;
} else {
for (int i = 0; i < output; i++) {
printf("%d\n", 1);
}
printf("%d\n", ans);
}
}
int main() {
char s[(int)1e5 + 10];
scanf("%s", s);
solve(s);
}
|
#include <bits/stdc++.h>
using namespace std;
string s;
int cnt, c, lst;
int main() {
cin >> s;
for (int i = 0; i < s.size(); i++)
if (s[i] == '#') cnt++, lst = i;
for (int i = 0; i <= lst; i++) {
if (s[i] == '(')
c++;
else
c--;
if (c < 0) {
cout << "-1\n";
return 0;
}
}
int f = c + 1;
c = 0;
for (int i = lst + 1; i < s.size(); i++) {
if (s[i] == '(')
c++;
else
c--;
if (c < 0) c++, f--;
}
if (c != 0 or f < 1)
cout << "-1\n";
else {
for (int i = 0; i < cnt - 1; i++) cout << "1\n";
cout << f;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> vec;
vector<pair<int, int>> vec2;
vector<pair<int, int>> vec3;
int arr[100010];
int arr2[100010];
int main() {
int i, j, o, cntm2fool = 0, cntmfto7 = 0, cntshbak = 0, num, sum = 0;
long long sum2 = 0, sum3 = 0, num2, cnt3 = 0, cnt4 = 0;
stack<char> s;
string ss;
cin >> ss;
for (i = 0; i < ss.size(); i++) {
if (ss[i] == '(') {
arr[i] = 1;
cntmfto7++;
s.push(ss[i]);
} else if (ss[i] == ')') {
if (s.size() == 0) {
cout << "-1" << endl;
return 0;
} else
cntm2fool++;
s.pop();
arr2[i] = 1;
} else if (ss[i] == '#') {
cntshbak++;
vec2.push_back(make_pair(i, cntmfto7));
vec3.push_back(make_pair(i, cntm2fool));
}
}
for (i = 0; i < vec2.size(); i++) sum2 += vec2[i].second;
for (i = 0; i < vec3.size(); i++) sum3 += vec3[i].second;
for (i = 1; i < ss.size(); i++) {
arr[i] += arr[i - 1];
}
if (cntshbak > 0) {
num = cntmfto7 - cntm2fool;
num2 = sum2 - sum3;
if (cntshbak > num) {
cout << "-1" << endl;
return 0;
} else if (num > num2) {
cout << "-1" << endl;
return 0;
}
for (j = 0; j < cntshbak - 1; j++) {
vec.push_back(1);
sum++;
arr2[vec3[j].first]++;
}
vec.push_back(num - sum);
arr2[vec3[vec3.size() - 1].first] += num - sum;
}
for (i = 1; i < ss.size(); i++) arr2[i] += arr2[i - 1];
for (i = 0; i < ss.size(); i++) {
if (arr2[i] > arr[i]) {
cout << "-1" << endl;
return 0;
}
}
if (ss[ss.size() - 1] == '(') {
cout << "-1" << endl;
return 0;
}
for (i = 0; i < vec.size(); i++) cout << vec[i] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string t, s = "";
cin >> t;
for (int i = 0; i < t.length(); i++) {
if (t[i] == '#') s += ')';
s += t[i];
}
int tab = 0;
int cur = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '#') tab++;
if (s[i] == '(') cur++;
if (s[i] == ')') cur--;
if (cur < 0) {
printf("-1\n");
return 0;
}
}
int lcur = cur;
int curtab = 0;
cur = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '#') {
curtab++;
if (curtab == tab) cur -= lcur;
}
if (s[i] == '(') cur++;
if (s[i] == ')') cur--;
if (cur < 0) {
printf("-1\n");
return 0;
}
}
for (int i = 0; i < tab - 1; i++) printf("1\n");
printf("%d\n", lcur + 1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int last, open = 0, close = 0, k, re = 0;
string s;
cin >> s;
last = s.rfind("#");
vector<char> v;
stack<char> S;
for (int i = 0; i < s.size(); i++)
if (s[i] == '(')
open++;
else if (s[i] == ')')
close++;
else
re++;
k = open - close;
if (k <= 0) {
cout << -1;
return 0;
}
for (int i = 0; i < s.size(); i++) {
if (s[i] == '(' || s[i] == ')') v.push_back(s[i]);
if (s[i] == '#' && i != last) {
v.push_back(s[i]);
k--;
} else if (s[i] == '#' && i == last) {
for (int i = 0; i < k; i++) {
v.push_back(')');
}
}
}
for (int i = 0; i < v.size(); i++) {
if (v[i] == '(')
S.push('(');
else {
if (!S.empty())
S.pop();
else {
cout << -1;
return 0;
}
}
}
if (S.size() != 0) {
cout << -1;
return 0;
}
int n = open - close;
for (int i = 0; i < re - 1; i++) {
cout << 1 << endl;
n--;
}
cout << n << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void fnc(string s) {
int l_i = s.size() - 1;
for (; l_i >= 0 && s[l_i] != '#'; l_i--) {
}
int extra = 0;
int fg = 0;
for (int i = l_i + 1; i < s.size(); i++) {
if (s[i] == ')')
extra++;
else
extra--;
}
int ct = 0;
vector<int> ans;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '(')
ct++;
else if (s[i] == ')')
ct--;
else if (i == l_i) {
ans.push_back(ct - extra);
ct = extra;
} else {
ans.push_back(1);
ct--;
}
if (ct < 0) {
fg = 1;
break;
}
}
if (ct || fg == 1) {
cout << "-1";
return;
}
for (int i = 0; i < ans.size(); i++) {
if (ans[i] <= 0) {
cout << "-1";
return;
}
}
for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
fnc(s);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string str;
int laz;
int pp;
int arr[100000];
int main() {
while (cin >> str) {
int ans = 0, temp = 0;
bool flag = 0;
for (int i = 0; i < str.length(); i++) {
if (str[i] == ')')
temp--;
else if (str[i] == '(')
temp++;
if (temp < 0) {
flag = 1;
break;
}
}
if (temp == 0) flag = 1;
if (!flag) {
laz = 0;
if (str == "#")
flag = 1;
else {
temp = 0;
for (int i = 0; i < str.length(); i++) {
if (str[i] == ')')
temp--;
else if (str[i] == '(')
temp++;
if (str[i] == '#') arr[laz++] = 1, temp--, pp = temp;
if (temp < 0) {
flag = 1;
break;
}
}
}
}
if (pp < temp || str[str.length() - 1] == '(') flag = 1;
if (flag)
puts("-1");
else {
for (int i = 0; i < laz - 1; i++) {
cout << arr[i] << endl;
}
cout << temp + 1 << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
string s;
int x, y, z, p, k, q, z1, z2;
int main() {
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '(')
x++;
else {
if (s[i] == ')')
y++;
else {
z++;
q = i;
}
}
if (x < y + z) {
cout << -1;
exit(0);
}
}
for (int i = s.length() - 1; i > q; i--) {
if (s[i] == ')')
z1++;
else
z2++;
if (z2 > z1) {
cout << -1;
exit(0);
}
}
int k = x - y;
for (int i = 0; i < z; i++) {
if (i != z - 1)
cout << 1 << endl;
else
cout << k - p;
p++;
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.