Submission #70646

# Submission time Handle Problem Language Result Execution time Memory
70646 2018-08-23T08:02:49 Z 구사과(#2191) Fibonacci representations (CEOI18_fib) C++11
0 / 100
6 ms 2184 KB
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int mod = 1e9 + 7;
const int MAXN = 200005;

set<int> s;
int n, a[MAXN];
int dp[MAXN][2];

int query(){
	n = 0;
	for(auto &i : s) a[++n] = i;
	dp[0][0] = 1;
	for(int i=1; i<=n; i++){
		int d = a[i] - a[i-1];
		dp[i][0] = (1ll * dp[i-1][1] * (d / 2 + 1) + 1ll * dp[i-1][0] * ((d + 1) / 2)) % mod;
		dp[i][1] = (1ll * dp[i-1][1] * (d / 2) + 1ll * dp[i-1][0] * ((d - 1) / 2)) % mod;
	}
	return dp[n][0];
}

void add(int x){ // does they amortize??? why???
	if(s.find(x) != s.end()){
		s.erase(x);
		add(x + 1);
		if(x > 2) add(x - 2);
		if(x == 2) add(1); 
		return;
	}
	s.insert(x);
	if(s.find(x + 1) != s.end()){
		s.erase(x);
		s.erase(x + 1);
		add(x + 2);
	}
	else if(s.find(x - 1) != s.end()){
		s.erase(x);
		s.erase(x - 1);
		add(x + 1);
	}
}

int f[MAXN];

int main(){
	f[1] = 1;
	f[2] = 2;
	for(int i=3; i<MAXN; i++){
		f[i] = (f[i-1] + f[i-2]) % mod;
	}
	int n, x, ans = 0;
	scanf("%d",&n);
	for(int i=0; i<n; i++){
		scanf("%d",&x);
		add(x);
		ans += f[x];
		ans %= mod;
		lint tmp = 0;
		for(auto &j : s) tmp += f[j];
		assert(ans == tmp % mod);
		printf("%d\n", query());
	}
}

Compilation message

fib.cpp: In function 'int main()':
fib.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
fib.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&x);
   ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1124 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 2184 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1016 KB Output isn't correct
2 Halted 0 ms 0 KB -