forked from iamvickynguyen/Kattis-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ada.cpp
62 lines (57 loc) · 1.15 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef unordered_set<int> usi;
typedef unordered_map<int, vi> ivi;
typedef unordered_map<int, int> ii;
typedef priority_queue<int> pq;
#define all(x) (x).begin(), (x).end()
#define pb push_back
void output(int cur, int degree, vi &last) {
for (int i = last.size() - 1; i >= 0; i--) {
cur += last[i];
}
cout << degree << " " << cur;
}
void solve(vi &v) {
vi tmp, cur = v;
vi last;
int degree = 1;
while (true) {
tmp.clear();
for (int i = 0; i < cur.size() - 1; i++) tmp.pb(cur[i + 1] - cur[i]);
if (tmp.size() == 0) {
output(v[v.size() - 1], degree, last);
return;
}
bool flag = true;
int val = tmp[0];
for (auto &diff: tmp) {
if (diff != val) {
flag = false;
break;
}
}
last.pb(tmp[tmp.size() - 1]);
if (flag) {
output(v[v.size() - 1], degree, last);
return;
}
cur = tmp;
degree++;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vi v(n);
for (auto &d: v) cin >> d;
solve(v);
return 0;
}