Submission #70647

# Submission time Handle Problem Language Result Execution time Memory
70647 2018-08-23T08:04:36 Z 김세빈(#2186) Fibonacci representations (CEOI18_fib) C++11
40 / 100
4000 ms 1336 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef __int128 lll;

const ll mod = 1e9 + 7;

lll F[1010];
vector <ll> A;
ll n;

ll calc(vector <ll> &V)
{
	ll i, k, p1, p2, _p1, _p2;
	
	p1 = 1, p2 = 0;
	
	for(i=V.size()-2; i>=0; i--){
		k = V[i] - V[i + 1];
		_p1 = (p1 + p2) % mod;
		if(k & 1) _p2 = (k / 2) * (p1 + p2) % mod;
		else _p2 = ((k / 2 - 1) * (p1 + p2) + p2) % mod;
		p1 = _p1, p2 = _p2;
	}
	
	return (p1 + p2) % mod;
}

ll f(lll v)
{
	vector <ll> V;
	
	ll i;
	
	for(i=120; i>=1; i--){
		if(F[i] <= v){
			v -= F[i];
			V.push_back(i);
		}
	}
	
	V.push_back(0);
	
	return calc(V);
}

int main()
{
	ll i, j, a;
	lll s;
	
	F[0] = F[1] = 1;
	for(i=2; i<=120; i++){
		F[i] = F[i - 1] + F[i - 2];
	}
	
	scanf("%lld", &n);
	
	s = 0;
	A.push_back(0);
	
	for(i=1; i<=n; i++){
		scanf("%lld", &a); if(a <= 120) s += F[a];
		
		A.push_back(a); sort(A.rbegin(), A.rend());
		for(j=0; j<A.size()-2; j++) if(A[j] <= A[j + 1] + 1) break;
		
		if(j == A.size() - 2) printf("%lld\n", calc(A));
		else printf("%lld\n", f(s));
	}
	
	return 0;
}

Compilation message

fib.cpp: In function 'int main()':
fib.cpp:68:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0; j<A.size()-2; j++) if(A[j] <= A[j + 1] + 1) break;
            ~^~~~~~~~~~~
fib.cpp:70:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(j == A.size() - 2) printf("%lld\n", calc(A));
      ~~^~~~~~~~~~~~~~~
fib.cpp:59:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
  ~~~~~^~~~~~~~~~~~
fib.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &a); if(a <= 120) s += F[a];
   ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 540 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 3 ms 564 KB Output is correct
6 Correct 3 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 540 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 3 ms 564 KB Output is correct
6 Correct 3 ms 564 KB Output is correct
7 Correct 3 ms 572 KB Output is correct
8 Correct 3 ms 748 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 540 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 3 ms 564 KB Output is correct
6 Correct 3 ms 564 KB Output is correct
7 Correct 3 ms 572 KB Output is correct
8 Correct 3 ms 748 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 3 ms 760 KB Output is correct
15 Correct 2 ms 760 KB Output is correct
16 Correct 3 ms 760 KB Output is correct
17 Correct 3 ms 760 KB Output is correct
18 Correct 3 ms 760 KB Output is correct
19 Incorrect 3 ms 760 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Execution timed out 4080 ms 1336 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 540 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 3 ms 564 KB Output is correct
6 Correct 3 ms 564 KB Output is correct
7 Correct 3 ms 572 KB Output is correct
8 Correct 3 ms 748 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 2 ms 760 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 3 ms 760 KB Output is correct
15 Correct 2 ms 760 KB Output is correct
16 Correct 3 ms 760 KB Output is correct
17 Correct 3 ms 760 KB Output is correct
18 Correct 3 ms 760 KB Output is correct
19 Incorrect 3 ms 760 KB Output isn't correct
20 Halted 0 ms 0 KB -