답안 #287581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
287581 2020-08-31T20:23:49 Z TadijaSebez Fibonacci representations (CEOI18_fib) C++11
15 / 100
4000 ms 1548 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
int add(int x,int y){x+=y;return x>=mod?x-mod:x;}
int mul(int x,int y){return (ll)x*y%mod;}
const int N=150;
map<int,int> cnt;
void Fix(int a){
	if(cnt[a]&&cnt[a-1]){
		cnt[a]--;
		cnt[a-1]--;
		cnt[a+1]++;
		Fix(a+1);
		Fix(a+2);
	}else if(cnt[a]==2){
		if(a==1){
			cnt[a]-=2;
			cnt[a+1]++;
			Fix(a+1);
			Fix(a+2);
		}else{
			cnt[max(a-2,1)]++;
			cnt[a]--;
			cnt[a+1]++;
			Fix(max(a-2,1));
			Fix(a-1);
			Fix(a+1);
			Fix(a+2);
		}
	}
}
int Solve(){
	int dp[2]={1,0},las=0;
	for(auto it:cnt){
		int i=it.first;
		if(!cnt[i])continue;
		int d0=add(dp[0],dp[1]);
		int sz=i-las-1;
		int d1=add(mul(dp[0],sz/2),mul(dp[1],(sz+1)/2));
		las=i;dp[0]=d0;dp[1]=d1;
	}
	return add(dp[0],dp[1]);
}
int main(){
	int n;
	scanf("%i",&n);
	for(int i=1;i<=n;i++){
		int a;
		scanf("%i",&a);
		cnt[a]++;
		Fix(a);
		Fix(a+1);
		printf("%i\n",Solve());
	}
	return 0;
}

Compilation message

fib.cpp: In function 'int main()':
fib.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |  scanf("%i",&n);
      |  ~~~~~^~~~~~~~~
fib.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   50 |   scanf("%i",&a);
      |   ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Execution timed out 4051 ms 1548 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -