Submission #813165

# Submission time Handle Problem Language Result Execution time Memory
813165 2023-08-07T14:02:40 Z Vladden Fibonacci representations (CEOI18_fib) C++14
0 / 100
4000 ms 312 KB
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
const int N = 107;
typedef long long ll;
const ll MOD = 1e9+7;
int A[N];
ll dp[N][2]; // 0 - prev was not split, 1 - prev was split
ll X(int n){
	if (n<0){
		return 0;
	}
	return (n+1)/2;
}
void normalize(int *A,int &n){
	multiset<int> S;
	for(int i = 1;i<=n;i+=1){
		S.insert(A[i]);
	}
	int ptr = 0;
	while(!S.empty()){
		int v = *S.begin();
		S.erase(S.begin());
		if (v==0 && S.count(v)!=0){
			S.erase(S.lower_bound(0));
			S.insert(1);
		}
		else if (S.count(v+1)!=0){
			S.erase(S.lower_bound(v+1));
			S.insert(v+2);
		}
		else{
			A[++ptr] = v;
		}
	}

	n = ptr;
}
int M[N];
bool compare(int *A,int *B,int sz){
	for(int i = 1;i<=sz;i+=1){
		if (A[i]!=B[i]){
			return 0;
		}
	}
	return 1;
}
ll calc(int &n){
	normalize(A,n);
	int ret = 0;
	for(int mask = 0;mask<(1<<(A[n]+1));mask+=1){
		int ptr = 0;
		for(int bit = 0;bit<A[n]+1;bit+=1){
			if (mask&(1<<bit)){
				M[++ptr] = bit;
			}
		}
		normalize(M,ptr);
		if (ptr==n && compare(A,M,ptr)){
			ret += 1;
		}
	}
	return ret;
}
ll solve(int &n){
	normalize(A,n);
	dp[0][0] = 1;
	for(int i = 1;i<=n;i+=1){
		dp[i][0] = (A[i-1]!=A[i]?dp[i-1][0]:0)+dp[i-1][1];
		dp[i][1] = dp[i-1][0]*X(A[i]-2-A[i-1])+dp[i-1][1]*X(A[i]-2-(A[i-1]-1));
		dp[i][0] %= MOD;
		dp[i][1] %= MOD;

	}
	return (dp[n][0]+dp[n][1])%MOD;
}
int main(){
	int n;
	cin>>n;
	int sz = 0;
	for(int i = 1;i<=n;i+=1){
		cin>>A[++sz];
		A[sz] -= 1;
		cout<<calc(sz)<<'\n';
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4051 ms 296 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4032 ms 312 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -