-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1248.cpp
More file actions
57 lines (56 loc) · 1.04 KB
/
1248.cpp
File metadata and controls
57 lines (56 loc) · 1.04 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
char v[56];
vector<int> ans;
int n;
bool isRight(int from,int to,char op){
int sum=0;
for(int i=from-1;i<to;i++)
sum+=ans[i];
if((sum>0&&op=='+')||(sum==0&&op=='0')||(sum<0&&op=='-'))
return true;
return false;
}
void go(int num){
if(num>n)
{
for(int i=0;i<ans.size();i++)
cout<<ans[i]<<" ";
cout<<"\n";
exit(0);
}
for(int i=-10;i<=10;i++)
{
int s=n-1;
int k=num;
bool flag=true;
ans.push_back(i);
for(int j=1;j<=num;j++)
{
if(isRight(j,num,v[k-1])){
k=k+s;
s--;
}
else{
ans.pop_back();
flag=false;
break;
}
}
if(flag)
{
go(num+1);
ans.pop_back();
}
}
}
int main(){
cin>>n;
for(int i=0;i<(n*(n+1))/2;i++)
{
cin>>v[i];
}
go(1);
}