Submission #823058

# Submission time Handle Problem Language Result Execution time Memory
823058 2023-08-12T07:28:08 Z MohamedAhmed04 Fibonacci representations (CEOI18_fib) C++14
50 / 100
4000 ms 4364 KB
#include <bits/stdc++.h>

using namespace std ;

const int mod = 1e9 + 7 ;

int Add(int x , int y)
{
	int z = x + y ;
	if(z >= mod)
		z -= mod ;
	return z ;
}

int Sub(int x , int y)
{
	int z = x - y ;
	if(z < 0)
		z += mod ;
	return z ;
}

int Mul(int x , int y)
{
	return (1ll * x * y) % mod ;
}

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
int n ;

map<int , int>freq ;
multiset<int>s ;

void Insert(int x)
{
	if(x < 0)
		return ;
	if(x == 0)
		x = 1 ;
	s.insert(x) , freq[x]++ ;
	if(freq[x] == 2)
	{
		s.erase(x) , freq[x] = 0 ;
		Insert(x-2) , Insert(x+1) ;
	}
	else if(freq[x-1])
	{
		s.erase(x-1) , s.erase(x) ;
		freq[x-1] = freq[x] = 0 ;
		Insert(x+1) ;
	}
	else if(freq[x+1])
	{
		s.erase(x) , s.erase(x+1) ;
		freq[x] = freq[x+1] = 0 ;
		Insert(x+2) ;
	}
}

int dp[MAX][2] ;

int solve(int idx)
{
	vector<int>v = {0} ;
	for(auto &x : s)
		v.push_back(x) ;
	int sz = v.size() ;
	dp[1][0] = (v[1] + 1) / 2 - 1 , dp[1][1] = 1 ;
	for(int i = 2 ; i < sz ; ++i)
	{
		dp[i][1] = Add(dp[i-1][0] , dp[i-1][1]) ;
		int x = (v[i] - v[i-1] + 1) / 2 ;
		dp[i][0] = Mul(x-1 , Add(dp[i-1][0] , dp[i-1][1])) ;
		if((v[i] % 2) == (v[i-1] % 2))
			dp[i][0] = Add(dp[i][0] , dp[i-1][0]) ;
	}
	return Add(dp[sz-1][0] , dp[sz-1][1]) ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	for(int i = 0 ; i < n ; ++i)
		cin>>arr[i] ;
	for(int i = 0 ; i < n ; ++i)
	{
		Insert(arr[i]) ;
		cout<<solve(i)<<"\n" ;
	}
	return 0 ;
}		
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 368 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Execution timed out 4059 ms 4364 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 368 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Execution timed out 4059 ms 4364 KB Time limit exceeded
26 Halted 0 ms 0 KB -