-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1248.cpp
More file actions
44 lines (40 loc) · 953 Bytes
/
1248.cpp
File metadata and controls
44 lines (40 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int arr[11];
char oper[11][11];
int n;
bool isPossible(int cnt) {
for (int i = 0; i < cnt; i++) {
int sum = 0;
for (int j = i; j < cnt; j++) {
sum += arr[j];
if (oper[i][j] == '-' && sum >= 0) return false;
if (oper[i][j] == '0' && sum != 0) return false;
if (oper[i][j] == '+' && sum <= 0) return false;
}
}
return true;
}
void solve(int cnt) {
if (cnt == n) {
for (int i = 0; i < n; i++) cout << arr[i] << " ";
exit(0);
}
for (int i = -10; i <= 10; i++) {
arr[cnt] = i;
if (isPossible(cnt + 1)) solve(cnt + 1);
}
}
int main() {
int idx = 0;
string s;
cin >> n >> s;
for (int i = 0; i < n; i++)
for (int j = i; j < n; j++) oper[i][j] = s[idx++];
solve(0);
return 0;
}