# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
943155 | vjudge1 | Fibonacci representations (CEOI18_fib) | C++17 | 4018 ms | 1364 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
vector <int> Delete(vector <int> v, int j) {
vector <int> res;
for (int i = 0; i < v.size(); i++) {
if (i == j) continue;
res.push_back(v[i]);
}
return res;
}
int main() {
int n;
cin >> n;
vector <int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector <int> vec;
for (int i = 1; i <= n; i++) {
vec.push_back(a[i]);
while (true) {
sort(vec.begin(), vec.end());
if (vec.size() > 1 && vec[0] == vec[1] && vec[0] == 1) {
vec.push_back(2);
vec = Delete(vec, 1);
vec = Delete(vec, 0);
continue;
}
bool repeat = 0;
for (int i = 1; i < vec.size(); i++) {
if (vec[i] == vec[i - 1] + 1) {
vec.push_back(vec[i] + 1);
vec = Delete(vec, i);
vec = Delete(vec, i - 1);
repeat = 1;
break;
}
}
if (!repeat) break;
}
sort(vec.begin(), vec.end());
int sz = (int)vec.size();
int dp[sz][2];
dp[0][0] = 1;
dp[0][1] = (vec[0] - 1) / 2;
for (int i = 1; i < sz; i++) {
if (vec[i - 1] != vec[i])
dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % mod;
else
dp[i][0] = dp[i - 1][1];
dp[i][1] = (1ll * ((vec[i] - 1 - vec[i - 1]) / 2) * dp[i][0]) % mod;
if (vec[i - 1] % 2 == vec[i] % 2) {
dp[i][1] += dp[i - 1][1];
dp[i][1] %= mod;
}
}
cout << (dp[sz - 1][0] + dp[sz - 1][1]) % mod << endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |