Submission #73358

# Submission time Handle Problem Language Result Execution time Memory
73358 2018-08-28T07:50:05 Z zscoder Fibonacci representations (CEOI18_fib) C++17
15 / 100
4000 ms 1444 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int MOD=1e9+7;

int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}

int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}

vector<int> getZeckendorf(vi a)
{
	sort(a.rbegin(),a.rend());
	while(1)
	{
		vi nw; bool reset=0;
		/*
		for(int x:a)
		{
			cerr<<x<<' ';
		}
		cerr<<'\n';
		*/
		for(int i=0;i<a.size();i++)
		{
			if(reset)
			{
				nw.pb(a[i]); continue;
			}
			if(i+1==int(a.size()))
			{
				nw.pb(a[i]); break;
			}
			if(a[i]==a[i+1])
			{
				if(a[i]==1)
				{
					nw.pb(2); i++; reset=1; continue;
				}
				else if(a[i]==2)
				{
					nw.pb(1); nw.pb(1); reset=1; continue;
				}
				else
				{
					nw.pb(a[i]-1); nw.pb(a[i]-2); reset=1; continue;
				}
			}
			else if(a[i]-a[i+1]==1)
			{
				nw.pb(a[i]+1); i++; reset=1;
			}
			else
			{
				nw.pb(a[i]); 
			}
		}
		sort(nw.rbegin(),nw.rend());
		a=nw;
		if(!reset) break;
	}
	return a;
}

int solve(vi vec) //solve given zeckendorf monkaS
{
	reverse(vec.begin(),vec.end());
	vector<int> dp[2];
	dp[0].assign(int(vec.size()),0);
	dp[1].assign(int(vec.size()),0);
	dp[0][0] = (vec[0]-1)/2;
	dp[1][0] = add(dp[0][0], 1);
	int n=vec.size();
	for(int i=1;i<n;i++)
	{
		int x=vec[i-1]; int y=vec[i];
		if((y-x)&1)
		{
			dp[1][i] = mult(dp[1][i-1], (y-x+1)/2);
			dp[0][i] = mult(dp[1][i-1], (y-x-1)/2);
		}
		else
		{
			dp[0][i] = add(mult((y-x)/2 - 1, dp[1][i-1]), dp[0][i-1]);
			dp[1][i] = add(mult((y-x)/2, dp[1][i-1]), dp[0][i-1]);
		}
	}
	return dp[1][n-1];
}

int a[111111];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	vi vec;
	for(int i=0;i<n;i++)
	{
		vec.pb(a[i]);
		vi nw = getZeckendorf(vec);
		cout<<solve(nw)<<'\n';
	}
}	

Compilation message

fib.cpp: In function 'std::vector<int> getZeckendorf(vi)':
fib.cpp:46:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<a.size();i++)
               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 3 ms 392 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Execution timed out 4043 ms 988 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 3 ms 392 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Execution timed out 4043 ms 988 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 2 ms 988 KB Output is correct
2 Correct 4 ms 988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 3 ms 392 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Execution timed out 4043 ms 988 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 4 ms 988 KB Output is correct
2 Execution timed out 4086 ms 1444 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 3 ms 392 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Execution timed out 4043 ms 988 KB Time limit exceeded