# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
121293 | bekzhan29 | Fibonacci representations (CEOI18_fib) | C++14 | 2 ms | 384 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>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define pb push_back
#define mp make_pair
#define INF 1e18
#define mod 1000000007
#define eps 1e-6
#define abs(x) ((x)>=0?(x):-(x))
#define y1 solai
#define fi first
#define se second
typedef long long ll;
void read(ll &x)
{
scanf("%lld",&x);
}
void read(ll &x, ll &y)
{
scanf("%lld%lld",&x,&y);
}
void read(ll &x, ll &y, ll &z)
{
scanf("%lld%lld%lld",&x,&y,&z);
}
void print(ll x)
{
printf("%lld ",x);
}
void println(ll x)
{
printf("%lld\n",x);
}
const ll N=300100;
ll n,x,last,cnt,ans,sum;
map<ll,ll>v;
void che(ll x)
{
if(x>1&&v.count(x)&&v.count(x-1))
{
v[x+1]++;
v.erase(x);
v.erase(x-1);
che(x+1);
}
if(v.count(x)&&v.count(x+1))
{
v[x+2]++;
v.erase(x);
v.erase(x+1);
che(x+2);
}
if(!v.count(x)||v[x]<2)
return;
if(x==1)
{
v[x+1]+=(v[x]>>1);
v[x]&=1;
if(v[x]==0)
v.erase(x);
che(x+1);
return;
}
if(x==2)
{
v[x-1]+=(v[x]>>1);
v[x+1]+=(v[x]>>1);
v[x]&=1;
if(v[x]==0)
v.erase(x);
che(x-1);
che(x+1);
return;
}
v[x-2]+=(v[x]>>1);
v[x+1]+=(v[x]>>1);
v[x]&=1;
if(v[x]==0)
v.erase(x);
che(x-2);
che(x+1);
}
int main()
{
cin>>n;
if(n>100)
return 0;
for(ll i=1;i<=n;i++)
{
read(x);
v[x]++;
che(x);
last=cnt=0;
ans=sum=1;
for(auto it:v)
{
if(it.first-2!=last)
{
ans*=sum;
ans%=mod;
sum=1;
cnt=(it.first-last-1)/2;
}
last=it.first;
sum+=cnt;
if(sum>=mod)
sum-=mod;
}
ans*=sum;
ans%=mod;
println(ans);
}
}
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... |