답안 #813272

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
813272 2023-08-07T14:53:35 Z Vladden Fibonacci representations (CEOI18_fib) C++14
50 / 100
4000 ms 872 KB
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
const int N = 1e5+7;
typedef long long ll;
const ll MOD = 1e9+7;
int A[N],base[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+2)/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(1){
		bool flag = false;
		for(auto it = S.rbegin();it!=S.rend();it = next(it)){
			int v = *it;
			if (S.count(v-1)){
				S.erase(S.lower_bound(v));
				S.erase(S.lower_bound(v-1));
				S.insert(v+1);
				flag = true;
				break;
			}
			else if (v>=2 && S.count(v)>=2){
				S.erase(S.lower_bound(v));
				S.erase(S.lower_bound(v));
				S.insert(v+1);
				S.insert(v-2);
				flag = true;
				break;
			}
			else if (S.count(v)==2 && v==1){
				S.erase(S.lower_bound(1));
				S.erase(S.lower_bound(1));
				S.insert(0);
				S.insert(2);
				flag = true;
				break;
			}
			else if (S.count(v)==2 && v==0){
				S.erase(S.lower_bound(0));
				S.erase(S.lower_bound(0));
				S.insert(1);
				flag = true;
				break;
			}

		}
		if (!flag){
			break;
		}
	}
	
	for(int to:S){
		A[++ptr] = to;
	}
	n = ptr;
}


ll solve(int &n){
	normalize(A,n);
	dp[0][0] = 1;
	A[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]-1)+dp[i-1][1]*X(A[i]-2-(A[i-1]-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<<solve(sz)<<'\n';
	/*	cout<<"GDB ";
		for(int i = 1;i<=sz;i+=1){
			cout<<A[i]<<' ';
		}
		cout<<'\n';*/
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 3 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 2 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 4043 ms 872 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 3 ms 212 KB Output is correct
21 Correct 2 ms 212 KB Output is correct
22 Correct 2 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Execution timed out 4043 ms 872 KB Time limit exceeded
26 Halted 0 ms 0 KB -