Submission #73396

# Submission time Handle Problem Language Result Execution time Memory
73396 2018-08-28T08:14:53 Z zscoder Fibonacci representations (CEOI18_fib) C++17
50 / 100
4000 ms 1604 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); i++; 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);
	srand(time(NULL));
	int n; cin>>n;
	//n=15; cout<<n<<endl;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		//a[i]=rand()%15+1;
		//cout<<a[i]<<' ';
	}
	//cout<<endl;
	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 3 ms 376 KB Output is correct
2 Correct 2 ms 524 KB Output is correct
3 Correct 2 ms 524 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 3 ms 528 KB Output is correct
6 Correct 2 ms 644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 524 KB Output is correct
3 Correct 2 ms 524 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 3 ms 528 KB Output is correct
6 Correct 2 ms 644 KB Output is correct
7 Correct 7 ms 644 KB Output is correct
8 Correct 8 ms 708 KB Output is correct
9 Correct 10 ms 708 KB Output is correct
10 Correct 7 ms 708 KB Output is correct
11 Correct 11 ms 708 KB Output is correct
12 Correct 10 ms 708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 708 KB Output is correct
2 Correct 4 ms 708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 524 KB Output is correct
3 Correct 2 ms 524 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 3 ms 528 KB Output is correct
6 Correct 2 ms 644 KB Output is correct
7 Correct 7 ms 644 KB Output is correct
8 Correct 8 ms 708 KB Output is correct
9 Correct 10 ms 708 KB Output is correct
10 Correct 7 ms 708 KB Output is correct
11 Correct 11 ms 708 KB Output is correct
12 Correct 10 ms 708 KB Output is correct
13 Correct 3 ms 708 KB Output is correct
14 Correct 4 ms 708 KB Output is correct
15 Correct 3 ms 708 KB Output is correct
16 Correct 10 ms 708 KB Output is correct
17 Correct 3 ms 708 KB Output is correct
18 Correct 2 ms 708 KB Output is correct
19 Correct 10 ms 708 KB Output is correct
20 Correct 7 ms 708 KB Output is correct
21 Correct 6 ms 708 KB Output is correct
22 Correct 6 ms 736 KB Output is correct
23 Correct 7 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 736 KB Output is correct
2 Execution timed out 4014 ms 1604 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 524 KB Output is correct
3 Correct 2 ms 524 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 3 ms 528 KB Output is correct
6 Correct 2 ms 644 KB Output is correct
7 Correct 7 ms 644 KB Output is correct
8 Correct 8 ms 708 KB Output is correct
9 Correct 10 ms 708 KB Output is correct
10 Correct 7 ms 708 KB Output is correct
11 Correct 11 ms 708 KB Output is correct
12 Correct 10 ms 708 KB Output is correct
13 Correct 3 ms 708 KB Output is correct
14 Correct 4 ms 708 KB Output is correct
15 Correct 3 ms 708 KB Output is correct
16 Correct 10 ms 708 KB Output is correct
17 Correct 3 ms 708 KB Output is correct
18 Correct 2 ms 708 KB Output is correct
19 Correct 10 ms 708 KB Output is correct
20 Correct 7 ms 708 KB Output is correct
21 Correct 6 ms 708 KB Output is correct
22 Correct 6 ms 736 KB Output is correct
23 Correct 7 ms 736 KB Output is correct
24 Correct 4 ms 736 KB Output is correct
25 Execution timed out 4014 ms 1604 KB Time limit exceeded
26 Halted 0 ms 0 KB -