답안 #468892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
468892 2021-08-30T07:05:11 Z superay Ancient Machine (JOI21_ancient_machine) C++17
100 / 100
69 ms 8580 KB
#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
long long dp[64];
void Init() {
	dp[0] = 1, dp[1] = 2;
	for (int i = 2; i <= 63; i++) dp[i] = dp[i - 1] + dp[i - 2];
}
long long Encode(const vector<int> &a, int l, int r) {
	if (l > r) return 0;
	if (l == r) return a[l];
	if (a[l]) return dp[r - l] + Encode(a, l + 2, r);
	else return Encode(a, l + 1, r);
}
}
void Anna(int n, vector<char> s) {
	Init();
	vector<int> res;
	for (int i = 0; i < n; i++) if (s[i] == 'X') {
		res.push_back(1);
		res.push_back(0);
		for (int j = i + 1; j < n; j++) res.push_back(s[j] == 'Z' && (j == n - 1 || s[j + 1] != 'Z'));
		break;
	} else res.push_back(0);
	if ((int)res.size() == n) return;
	while (res.size() % 63) res.push_back(0);
	for (int i = 0; i < (int)res.size(); i += 63) {
		long long cur = Encode(res, i, i + 62);
		for (int j = 43; j >= 0; j--) Send(cur >> j & 1);
	}
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
long long dp[64];
void Init() {
	dp[0] = 1, dp[1] = 2;
	for (int i = 2; i <= 63; i++) dp[i] = dp[i - 1] + dp[i - 2];
}
void Decode(vector<int> &a, long long cur, int l) {
	if (!l) return;
	if (l == 1) a.push_back(cur);
	else if (cur < dp[l - 1]) a.push_back(0), Decode(a, cur, l - 1);
	else a.push_back(1), a.push_back(0), Decode(a, cur - dp[l - 1], l - 2);
}
}
void Bruno(int n, int l, vector<int> a) {
	if (a.empty()) {
		for (int i = 0; i < n; i++) Remove(i);
		return;
	}
	Init();
	vector<int> res;
	for (int i = 0; i < l; i += 44) {
		long long cur = 0;
		for (int j = 0; j < 44; j++) if (a[i + j]) cur |= (1ll << (43 - j));
		Decode(res, cur, 63);
	}
	while ((int)res.size() > n + 1) res.pop_back();
	for (int i = 0; i < n; i++) if (res[i]) {
		res.erase(res.begin() + i + 1);
		for (int j = i - 1; j >= 0; j--) Remove(j);
		int lst = i;
		for (int j = i + 1; j < n; j++) if (res[j]) {
			for (int k = j - 1; k > lst; k--) Remove(k);
			Remove(j);
			lst = j;
		}
		for (int j = lst + 1; j < n; j++) Remove(j);
		Remove(i);
		break;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 488 KB Output is correct
2 Correct 1 ms 496 KB Output is correct
3 Correct 0 ms 488 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 0 ms 488 KB Output is correct
6 Correct 1 ms 488 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 488 KB Output is correct
9 Correct 1 ms 488 KB Output is correct
10 Correct 1 ms 496 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 8356 KB Output is correct
2 Correct 60 ms 8484 KB Output is correct
3 Correct 61 ms 8500 KB Output is correct
4 Correct 57 ms 8268 KB Output is correct
5 Correct 65 ms 8332 KB Output is correct
6 Correct 60 ms 8372 KB Output is correct
7 Correct 62 ms 8332 KB Output is correct
8 Correct 60 ms 8372 KB Output is correct
9 Correct 61 ms 8280 KB Output is correct
10 Correct 57 ms 8352 KB Output is correct
11 Correct 60 ms 8304 KB Output is correct
12 Correct 57 ms 8396 KB Output is correct
13 Correct 65 ms 8424 KB Output is correct
14 Correct 68 ms 8580 KB Output is correct
15 Correct 67 ms 8432 KB Output is correct
16 Correct 66 ms 8452 KB Output is correct
17 Correct 66 ms 8492 KB Output is correct
18 Correct 52 ms 7384 KB Output is correct
19 Correct 51 ms 7396 KB Output is correct
20 Correct 59 ms 8396 KB Output is correct
21 Correct 62 ms 8384 KB Output is correct
22 Correct 67 ms 8532 KB Output is correct
23 Correct 60 ms 8296 KB Output is correct
24 Correct 57 ms 8392 KB Output is correct
25 Correct 53 ms 7344 KB Output is correct
26 Correct 64 ms 8368 KB Output is correct
27 Correct 69 ms 8480 KB Output is correct
28 Correct 66 ms 8320 KB Output is correct
29 Correct 51 ms 7348 KB Output is correct
30 Correct 65 ms 8304 KB Output is correct
31 Correct 51 ms 7264 KB Output is correct
32 Correct 59 ms 8416 KB Output is correct
33 Correct 60 ms 8412 KB Output is correct