-
Notifications
You must be signed in to change notification settings - Fork 0
/
day25.cpp
54 lines (53 loc) · 1.2 KB
/
day25.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define int long long
long long sum;
long long dp[22],dpsum[22];
void dfs(int x,int res,string ans){
if(x==-1){
if(res == sum){
cout << ans << endl;
exit(0);
}
return;
}
int val = 2*dpsum[x];
if(val+res<sum)return;
if(res-val>sum)return;
dfs(x-1,res,ans+"0");
dfs(x-1,res-dp[x],ans+"-");
dfs(x-1,res-2*dp[x],ans+"=");
dfs(x-1,res+dp[x],ans+"1");
dfs(x-1,res+2*dp[x],ans+"2");
}
int32_t main() {
freopen("input.txt","r",stdin);
int lines = 115;
vector <int> v;
sum = 0;
for(int ij=0;ij<lines;ij++){
string s;cin >> s;
int res = 0;
int ik = 1;
for(int i = s.length()-1;i>=0;i--){
if(s[i] == '-'){
res = res - ik;
}
else if(s[i] == '='){
res = res - ik*2;
}
else{
res = res + (s[i]-'0')*ik;
}
ik = ik*5;
}
sum = sum + res;
}
dp[0] = 1 + 0LL;
dpsum[0] = 1 + 0LL;
for(int32_t i=1;i<22;i++){
dp[i] = dp[i-1]*5;
dpsum[i] = dpsum[i-1] + dp[i];
}
dfs(19,0,"");
}