답안 #655899

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
655899 2022-11-06T01:34:23 Z gs12117 Broken Device 2 (JOI22_device2) C++17
100 / 100
80 ms 3016 KB
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <random>

int Declare() {
	int max_m = 139;
	return max_m;
}

std::pair<std::vector<int>, std::vector<int> > Anna(long long A) {
	int max_m = 139;
	long long int dp[200];
	for (int i = 0; i < max_m; i++) {
		if (i < 5)dp[i] = i + 1;
		else dp[i] = dp[i - 2] + dp[i - 3];
	}
	int sz = 0;
	for (int i = max_m - 3; i >= 0; i--) {
		if (A < dp[i] * 4) {
			sz = i;
			break;
		}
		A -= dp[i] * 4;
	}
	int invt = 0;
	if (A >= dp[sz] * 2) {
		A -= dp[sz] * 2;
		invt = 1;
	}
	std::vector<int> X;
	std::vector<int> Y;
	for (int i = 0; i < sz + 3; i++) {
		Y.push_back((sz + i) % 2); // last Y[sz+2]=0
	}
	if (A >= dp[sz]) {
		A -= dp[sz];
		X.push_back(1);
		X.push_back(1);
	}
	else {
		X.push_back(0);
		X.push_back(0);
	}
	int p = sz;
	while (1) {
		if (p < 5) {
			for (int i = 0; i < p; i++) {
				if (i < A)X.push_back(1);
				else X.push_back(0);
			}
			break;
		}
		else {
			if (A >= dp[p - 2]) {
				A -= dp[p - 2];
				X.push_back(1 - X[X.size() - 1]);
				p--;
			}
			X.push_back(X[X.size() - 1]);
			X.push_back(X[X.size() - 1]);
			p -= 2;
		}
	}
	X.push_back(0);
	if (invt == 1) {
		for (int i = 0; i < sz + 3; i++) {
			X[i] = 1 - X[i];
			Y[i] = 1 - Y[i];
		}
	}
	return make_pair(X, Y);
}
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <random>

long long Bruno(std::vector<int> u) {
	int max_m = 139;
	long long int dp[200];
	for (int i = 0; i < max_m; i++) {
		if (i < 5)dp[i] = i + 1;
		else dp[i] = dp[i - 2] + dp[i - 3];
	}
	int sz = u.size() / 2 - 3;
	long long int ans = 0;
	for (int i = max_m - 3; i >= 0; i--) {
		if (i == sz) {
			break;
		}
		ans += dp[i] * 4;
	}
	std::vector<int> v = u;
	if (u[u.size() - 1] == 1) {
		ans += dp[sz] * 2;
		for (int i = 0; i < v.size(); i++) {
			v[i] = 1 - v[i];
		}
	}
	int sumv = 0;
	for (int i = 0; i < v.size(); i++) {
		sumv += v[i];
	}
	sumv -= (sz + 3) / 2;
	int curmax = 0;
	int curmin = 0;
	int curv = 0;
	if (sz % 2 == 1) {
		curmax = 1;
	}
	else {
		curmin = -1;
	}
	int p = 0;
	for (; p < v.size();) {
		curv += 2 * v[p] - 1;
		p++;
		if (curv > curmax || curv < curmin) {
			break;
		}
	}
	int lastv = 0;
	int szleft = sz;
	if (curv > curmax) {
		ans += dp[sz];
		lastv = 1;
		sumv -= 2;
	}
	curmax = curv + 1;
	curmin = curv - 1;
	while (szleft >= 5) {
		curv += 2 * v[p] - 1;
		p++;
		if (curv > curmax) {
			if (lastv == 0) {
				ans += dp[szleft - 2];
				szleft--;
				sumv--;
			}
			lastv = 1;
			curmax = curv + 1;
			curmin = curv - 1;
			szleft -= 2;
			sumv -= 2;
		}
		else if (curv < curmin) {
			if (lastv == 1) {
				ans += dp[szleft - 2];
				szleft--;
			}
			lastv = 0;
			curmax = curv + 1;
			curmin = curv - 1;
			szleft -= 2;
		}
	}
	ans += sumv;
	return ans;
}

Compilation message

Bruno.cpp: In function 'long long int Bruno(std::vector<int>)':
Bruno.cpp:24:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   for (int i = 0; i < v.size(); i++) {
      |                   ~~^~~~~~~~~~
Bruno.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for (int i = 0; i < v.size(); i++) {
      |                  ~~^~~~~~~~~~
Bruno.cpp:43:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for (; p < v.size();) {
      |         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 508 KB Output is correct
2 Correct 65 ms 2704 KB Output is correct
3 Correct 63 ms 2752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 508 KB Output is correct
2 Correct 65 ms 2704 KB Output is correct
3 Correct 63 ms 2752 KB Output is correct
4 Correct 68 ms 2900 KB Output is correct
5 Correct 62 ms 2744 KB Output is correct
6 Correct 66 ms 2664 KB Output is correct
7 Correct 80 ms 2724 KB Output is correct
8 Correct 63 ms 2732 KB Output is correct
9 Correct 63 ms 2736 KB Output is correct
10 Correct 61 ms 2752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 508 KB Output is correct
2 Correct 65 ms 2704 KB Output is correct
3 Correct 63 ms 2752 KB Output is correct
4 Correct 68 ms 2900 KB Output is correct
5 Correct 62 ms 2744 KB Output is correct
6 Correct 66 ms 2664 KB Output is correct
7 Correct 80 ms 2724 KB Output is correct
8 Correct 63 ms 2732 KB Output is correct
9 Correct 63 ms 2736 KB Output is correct
10 Correct 61 ms 2752 KB Output is correct
11 Correct 70 ms 2848 KB Output is correct
12 Correct 64 ms 2764 KB Output is correct
13 Correct 64 ms 2744 KB Output is correct
14 Correct 63 ms 2920 KB Output is correct
15 Correct 65 ms 2684 KB Output is correct
16 Correct 63 ms 2708 KB Output is correct
17 Correct 60 ms 2664 KB Output is correct
18 Correct 64 ms 2816 KB Output is correct
19 Correct 62 ms 2900 KB Output is correct
20 Correct 66 ms 2700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 508 KB Output is correct
2 Correct 65 ms 2704 KB Output is correct
3 Correct 63 ms 2752 KB Output is correct
4 Correct 68 ms 2900 KB Output is correct
5 Correct 62 ms 2744 KB Output is correct
6 Correct 66 ms 2664 KB Output is correct
7 Correct 80 ms 2724 KB Output is correct
8 Correct 63 ms 2732 KB Output is correct
9 Correct 63 ms 2736 KB Output is correct
10 Correct 61 ms 2752 KB Output is correct
11 Correct 70 ms 2848 KB Output is correct
12 Correct 64 ms 2764 KB Output is correct
13 Correct 64 ms 2744 KB Output is correct
14 Correct 63 ms 2920 KB Output is correct
15 Correct 65 ms 2684 KB Output is correct
16 Correct 63 ms 2708 KB Output is correct
17 Correct 60 ms 2664 KB Output is correct
18 Correct 64 ms 2816 KB Output is correct
19 Correct 62 ms 2900 KB Output is correct
20 Correct 66 ms 2700 KB Output is correct
21 Correct 63 ms 2756 KB Output is correct
22 Correct 67 ms 2776 KB Output is correct
23 Correct 64 ms 2760 KB Output is correct
24 Correct 74 ms 2812 KB Output is correct
25 Correct 63 ms 2900 KB Output is correct
26 Correct 62 ms 2816 KB Output is correct
27 Correct 59 ms 2732 KB Output is correct
28 Correct 68 ms 2892 KB Output is correct
29 Correct 67 ms 2720 KB Output is correct
30 Correct 70 ms 2736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 508 KB Output is correct
2 Correct 65 ms 2704 KB Output is correct
3 Correct 63 ms 2752 KB Output is correct
4 Correct 68 ms 2900 KB Output is correct
5 Correct 62 ms 2744 KB Output is correct
6 Correct 66 ms 2664 KB Output is correct
7 Correct 80 ms 2724 KB Output is correct
8 Correct 63 ms 2732 KB Output is correct
9 Correct 63 ms 2736 KB Output is correct
10 Correct 61 ms 2752 KB Output is correct
11 Correct 70 ms 2848 KB Output is correct
12 Correct 64 ms 2764 KB Output is correct
13 Correct 64 ms 2744 KB Output is correct
14 Correct 63 ms 2920 KB Output is correct
15 Correct 65 ms 2684 KB Output is correct
16 Correct 63 ms 2708 KB Output is correct
17 Correct 60 ms 2664 KB Output is correct
18 Correct 64 ms 2816 KB Output is correct
19 Correct 62 ms 2900 KB Output is correct
20 Correct 66 ms 2700 KB Output is correct
21 Correct 63 ms 2756 KB Output is correct
22 Correct 67 ms 2776 KB Output is correct
23 Correct 64 ms 2760 KB Output is correct
24 Correct 74 ms 2812 KB Output is correct
25 Correct 63 ms 2900 KB Output is correct
26 Correct 62 ms 2816 KB Output is correct
27 Correct 59 ms 2732 KB Output is correct
28 Correct 68 ms 2892 KB Output is correct
29 Correct 67 ms 2720 KB Output is correct
30 Correct 70 ms 2736 KB Output is correct
31 Correct 61 ms 2668 KB Output is correct
32 Correct 70 ms 2828 KB Output is correct
33 Correct 71 ms 2852 KB Output is correct
34 Correct 73 ms 2840 KB Output is correct
35 Correct 69 ms 2824 KB Output is correct
36 Correct 62 ms 2756 KB Output is correct
37 Correct 66 ms 2660 KB Output is correct
38 Correct 70 ms 2932 KB Output is correct
39 Correct 71 ms 2824 KB Output is correct
40 Correct 62 ms 2844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 2848 KB Output is correct
2 Correct 64 ms 2844 KB Output is correct
3 Correct 66 ms 2836 KB Output is correct
4 Correct 62 ms 2724 KB Output is correct
5 Correct 66 ms 2740 KB Output is correct
6 Correct 66 ms 2892 KB Output is correct
7 Correct 64 ms 2792 KB Output is correct
8 Correct 63 ms 2832 KB Output is correct
9 Correct 68 ms 2752 KB Output is correct
10 Correct 69 ms 2668 KB Output is correct
11 Correct 65 ms 2792 KB Output is correct
12 Correct 61 ms 2756 KB Output is correct
13 Correct 59 ms 2584 KB Output is correct
14 Correct 59 ms 2692 KB Output is correct
15 Correct 67 ms 2680 KB Output is correct
16 Correct 67 ms 2944 KB Output is correct
17 Correct 64 ms 3016 KB Output is correct
18 Correct 63 ms 2664 KB Output is correct
19 Correct 78 ms 2752 KB Output is correct
20 Correct 62 ms 2684 KB Output is correct