답안 #655897

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
655897 2022-11-06T01:28:10 Z gs12117 Broken Device 2 (JOI22_device2) C++17
40 / 100
76 ms 3012 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] * 2;
		lastv = 1;
	}
	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 2 ms 512 KB Output is correct
2 Correct 76 ms 3012 KB Output is correct
3 Correct 62 ms 2812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 76 ms 3012 KB Output is correct
3 Correct 62 ms 2812 KB Output is correct
4 Correct 63 ms 2716 KB Output is correct
5 Correct 63 ms 2828 KB Output is correct
6 Correct 71 ms 2704 KB Output is correct
7 Correct 65 ms 2844 KB Output is correct
8 Correct 63 ms 2716 KB Output is correct
9 Correct 60 ms 2784 KB Output is correct
10 Correct 64 ms 2720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 76 ms 3012 KB Output is correct
3 Correct 62 ms 2812 KB Output is correct
4 Correct 63 ms 2716 KB Output is correct
5 Correct 63 ms 2828 KB Output is correct
6 Correct 71 ms 2704 KB Output is correct
7 Correct 65 ms 2844 KB Output is correct
8 Correct 63 ms 2716 KB Output is correct
9 Correct 60 ms 2784 KB Output is correct
10 Correct 64 ms 2720 KB Output is correct
11 Correct 72 ms 2848 KB Output is correct
12 Correct 63 ms 2904 KB Output is correct
13 Correct 62 ms 2744 KB Output is correct
14 Correct 62 ms 2648 KB Output is correct
15 Correct 62 ms 2724 KB Output is correct
16 Correct 69 ms 2740 KB Output is correct
17 Correct 68 ms 2792 KB Output is correct
18 Correct 61 ms 2756 KB Output is correct
19 Correct 61 ms 2760 KB Output is correct
20 Correct 61 ms 2748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 76 ms 3012 KB Output is correct
3 Correct 62 ms 2812 KB Output is correct
4 Correct 63 ms 2716 KB Output is correct
5 Correct 63 ms 2828 KB Output is correct
6 Correct 71 ms 2704 KB Output is correct
7 Correct 65 ms 2844 KB Output is correct
8 Correct 63 ms 2716 KB Output is correct
9 Correct 60 ms 2784 KB Output is correct
10 Correct 64 ms 2720 KB Output is correct
11 Correct 72 ms 2848 KB Output is correct
12 Correct 63 ms 2904 KB Output is correct
13 Correct 62 ms 2744 KB Output is correct
14 Correct 62 ms 2648 KB Output is correct
15 Correct 62 ms 2724 KB Output is correct
16 Correct 69 ms 2740 KB Output is correct
17 Correct 68 ms 2792 KB Output is correct
18 Correct 61 ms 2756 KB Output is correct
19 Correct 61 ms 2760 KB Output is correct
20 Correct 61 ms 2748 KB Output is correct
21 Correct 60 ms 2828 KB Output is correct
22 Correct 68 ms 2836 KB Output is correct
23 Correct 65 ms 2772 KB Output is correct
24 Correct 61 ms 2828 KB Output is correct
25 Correct 61 ms 2764 KB Output is correct
26 Correct 61 ms 2748 KB Output is correct
27 Correct 61 ms 2800 KB Output is correct
28 Correct 62 ms 2724 KB Output is correct
29 Correct 63 ms 2716 KB Output is correct
30 Correct 70 ms 2764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 76 ms 3012 KB Output is correct
3 Correct 62 ms 2812 KB Output is correct
4 Correct 63 ms 2716 KB Output is correct
5 Correct 63 ms 2828 KB Output is correct
6 Correct 71 ms 2704 KB Output is correct
7 Correct 65 ms 2844 KB Output is correct
8 Correct 63 ms 2716 KB Output is correct
9 Correct 60 ms 2784 KB Output is correct
10 Correct 64 ms 2720 KB Output is correct
11 Correct 72 ms 2848 KB Output is correct
12 Correct 63 ms 2904 KB Output is correct
13 Correct 62 ms 2744 KB Output is correct
14 Correct 62 ms 2648 KB Output is correct
15 Correct 62 ms 2724 KB Output is correct
16 Correct 69 ms 2740 KB Output is correct
17 Correct 68 ms 2792 KB Output is correct
18 Correct 61 ms 2756 KB Output is correct
19 Correct 61 ms 2760 KB Output is correct
20 Correct 61 ms 2748 KB Output is correct
21 Correct 60 ms 2828 KB Output is correct
22 Correct 68 ms 2836 KB Output is correct
23 Correct 65 ms 2772 KB Output is correct
24 Correct 61 ms 2828 KB Output is correct
25 Correct 61 ms 2764 KB Output is correct
26 Correct 61 ms 2748 KB Output is correct
27 Correct 61 ms 2800 KB Output is correct
28 Correct 62 ms 2724 KB Output is correct
29 Correct 63 ms 2716 KB Output is correct
30 Correct 70 ms 2764 KB Output is correct
31 Correct 64 ms 2820 KB Output is correct
32 Correct 68 ms 2744 KB Output is correct
33 Correct 71 ms 2784 KB Output is correct
34 Correct 63 ms 2816 KB Output is correct
35 Correct 63 ms 2804 KB Output is correct
36 Correct 71 ms 2764 KB Output is correct
37 Correct 66 ms 2820 KB Output is correct
38 Correct 63 ms 2724 KB Output is correct
39 Correct 62 ms 2772 KB Output is correct
40 Correct 66 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 65 ms 2744 KB Output isn't correct
2 Halted 0 ms 0 KB -