forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ada.cpp
50 lines (40 loc) · 890 Bytes
/
ada.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
#include <iostream>
#include <vector>
using namespace std;
int depth = 0;
vector<int> isequal(vector<int> v) {
depth++;
int num = v[0];
bool same = true;
for(auto i : v) {
if(i != num) {
same = false;
}
}
if(same) {
v.push_back(num);
return v;
}
else {
vector<int> temp;
for(int i = 0; i < v.size()-1; i++) {
temp.push_back(v[i] - v[i+1]);
}
temp = isequal(temp);
v.push_back(v[v.size()-1] - temp[temp.size()-1]);
//v.push_back(v[v.size()-1] + temp[temp.size()-1]);
return v;
}
}
int main() {
int n;
cin >> n;
vector<int> v;
for(int i = 0; i < n; i++) {
int num;
cin >> num;
v.push_back(num);
}
vector<int> ans = isequal(v);
cout << depth-1 << " " << ans[ans.size()-1] << endl;
}