# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
93403 | Kastanda | Fibonacci representations (CEOI18_fib) | C++11 | 2 ms | 376 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>
#define pb push_back
using namespace std;
const int N = 100005, Mod = 1e9 + 7;
int n, A[N];
set < int > B;
inline void Add(int a)
{
if (a < 0)
return ;
if (a == 0)
{
Add(1);
return ;
}
if (B.count(a))
{
B.erase(a);
Add(a + 1);
Add(a - 2);
return ;
}
if (B.count(a - 1))
{
B.erase(a - 1);
Add(a + 1);
return ;
}
if (B.count(a + 1))
{
B.erase(a + 1);
Add(a + 2);
return ;
}
B.insert(a);
}
inline int Solve()
{
int a = 1, b = 0;
for (auto it = B.begin(); it != B.end(); it ++)
{
int cz = (*it) - 1;
if (it != B.begin())
{
it --;
cz -= *it;
it ++;
}
a = (a + b) % Mod;
b = (1LL * (cz >> 1) * a + 1LL * ((cz + 1) >> 1) * b) % Mod;
}
return ((a + b) % Mod);
}
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf("%d", &A[i]);
Add(A[i]);
printf("%d\n", Solve());
}
return (0);
}
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... |