답안 #128632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
128632 2019-07-11T07:49:33 Z 조승현(#3164) Fibonacci representations (CEOI18_fib) C++14
50 / 100
73 ms 492 KB
#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
#include<deque>
using namespace std;
map<int, int>Map;
int n;
void Handle(int a) {
	if (a == 1) {
		Map[a] = 0;
		Map[a + 1]++;
	}
	else if (a == 2) {
		Map[a - 1]++, Map[a + 1]++;
		Map[a] = 0;
	}
	else {
		Map[a - 2]++, Map[a + 1]++;
		Map[a] = 0;
		if (Map[a - 2] == 2)Handle(a - 2);
	}
}
long long D[1010][2], Mod = 1000000007;
void Add(int a, int b) {
	Map[a] += b;
	if (Map[a] == 2) {
		Handle(a);
	}
	deque<int>TP;
	vector<int>w;
	for (auto &tp : Map) {
		if (tp.second)TP.push_back(tp.first);
	}
	int i, j;
	while (!TP.empty()) {
		for (j = 0; j < TP.size() && TP[j] - TP[0] == j; j++);
		int b = TP[0], e = TP[j - 1];
		if (b == e) {
			w.push_back(TP.front());
			TP.pop_front();
			continue;
		}
		for (j = b; j <= e; j++)TP.pop_front();
		vector<int>TT;
		if ((e - b) % 2 == 0) {
			TT.push_back(b);
			b += 3;
			while (b <= e + 1) {
				TT.push_back(b);
				b += 2;
			}
		}
		else {
			while (b <= e - 1) {
				b += 2;
				TT.push_back(b);
			}
		}
		for (j = TT.size() - 1; j >= 0; j--)TP.push_front(TT[j]);
	}
	D[0][0] = 1;
	D[0][1] = (w[0] - 1) / 2;
	for (i = 1; i < w.size(); i++) {
		int d = w[i] - w[i - 1];
		D[i][0] = (D[i - 1][0] + D[i - 1][1]) % Mod;
		D[i][1] = (((d - 1) / 2) * D[i - 1][0] + (d / 2)*D[i - 1][1]) % Mod;
	}
	printf("%lld\n", (D[w.size() - 1][0] + D[w.size() - 1][1]) % Mod);
	Map.clear();
	for (auto &x : w)Map[x] = 1;

}
int main() {
	int i, a;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a);
		Add(a, 1);
	}
}

Compilation message

fib.cpp: In function 'void Add(int, int)':
fib.cpp:37:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (j = 0; j < TP.size() && TP[j] - TP[0] == j; j++);
               ~~^~~~~~~~~~~
fib.cpp:64:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 1; i < w.size(); i++) {
              ~~^~~~~~~~~~
fib.cpp: In function 'int main()':
fib.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
fib.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a);
   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 3 ms 256 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 KB Output is correct
2 Runtime error 73 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 3 ms 256 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 256 KB Output is correct
25 Runtime error 73 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
26 Halted 0 ms 0 KB -