-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday09.cpp
73 lines (64 loc) · 1.26 KB
/
day09.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
lengli_QAQ
Hope there are no bugs!!!
*/
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
#define all(x) x.begin(),x.end()
#define pb push_back
#define int long long
using namespace std;
//--------------------------------
template<typename T> void printvt(vector<T> &a){
for(auto x:a) cout<<x<<" ";cout<<endl;
};
template<typename T> void printay(T a[],int l,int r){
for(int i=l;i<=r;i++) cout<<a[i]<<" ";cout<<endl;
};
//--------------------------------
typedef pair<int,int> PII;
typedef long long LL;
const int N=100010;
int check(string s){
stringstream sin(s);
vector<vector<int>> b;
vector<int> a;
int x;
set<int> st;
while(sin>>x) a.pb(x),st.insert(x);
b.pb(a);
while(*st.begin()!=0 or st.size()!=1){
st.clear();
a.clear();
auto t=b.back();
for(int i=1;i<t.size();i++) {
a.pb(t[i]-t[i-1]);
st.insert(t[i]-t[i-1]);
}
b.pb(a);
}
for(auto &x:b) reverse(all(x));
for(int i=b.size()-1;i>0;i--){
auto t=b[i].back();
b[i-1].pb(b[i-1].back()-t);
}
return b[0].back();
}
void solve(){
string s;
int res=0;
while(getline(cin,s)){
int t=check(s);
cout<<t<<endl;
res+=t;
}
cout<<res;
}
signed main(){
fastio;
int T;
T=1;
while(T--) solve();
return 0;
}