답안 #940063

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940063 2024-03-07T04:55:18 Z lamter Ancient Machine (JOI21_ancient_machine) C++17
5 / 100
40 ms 8332 KB
#include "Anna.h"
#include <bits/stdc++.h>

void Anna(int n, std::vector <char> a) {
	const int kFibonacci = 63;
	const int kLog = 44;
	std::vector <long long> dp(kFibonacci);
	dp[0] = 1;
	dp[1] = 2;
	for (int i = 2; i < kFibonacci; i += 1) {
		dp[i] = dp[i - 1] + dp[i - 2];
	}
	std::vector <int> b(n);
	bool found = 0;
	for (int i = 0; i < n; i += 1) {
		int bit = 0;

		if (not found and a[i] == 'X') {
			bit = 1;
			found = true;
		}

		if (found and a[i] == 'Z' and (i + 1 == n or a[i + 1] != 'Z') and (b[i - 1] != 1)) {
			bit = 1;
		}

		b[i] = bit;
	}

	auto SendEncode = [&] (std::vector <int> z) -> void {
		long long x = 0;
		for (int i = 0; i < kFibonacci; i += 1) {
			x += z[i] ? dp[i] : 0;
		}
		assert((1LL << kLog) - 1 >= x);
		for (int i = 0; i < kLog; i += 1) {
			Send((x >> i) & 1);
		}
	};

	while (b.size() % kFibonacci)
		b.push_back(0);
	for (int l = 0, r = kFibonacci; r <= (int) b.size(); l += kFibonacci, r += kFibonacci) {
		SendEncode(std::vector <int> (b.begin() + l, b.begin() + r));
	}
}
#include "Bruno.h"
#include <bits/stdc++.h>

void Bruno(int n, int, std::vector <int> a) {
	const int kFibonacci = 63;
	const int kLog = 44;
	std::vector <long long> dp(kFibonacci);
	dp[0] = 1;
	dp[1] = 2;
	for (int i = 2; i < kFibonacci; i += 1) {
		dp[i] = dp[i - 1] + dp[i - 2];
	}
	std::vector <int> posOne;

	for (int l = 0, r = kLog; r <= (int) a.size(); l += kLog, r += kLog) {
		long long x = 0;
		for (int i = l; i < r; i += 1)
			x += (1LL * a[i]) << (i - l);
		int p = l / kLog;
		for (int i = kFibonacci - 1; i >= 0; i -= 1) {
			if (x >= dp[i]) {
				x -= dp[i];
				posOne.push_back(p * kFibonacci + i);
			}
		}
		assert(x == 0);
	}
	std::sort(posOne.begin(), posOne.end());

	if (posOne.size() < 2) {
		for (int i = 0; i < n; i += 1)
			Remove(i);
		return;
	}
	int x = posOne[0];
	for (int i = 0; i < x; i += 1) {
		Remove(i);
	}
	for (int i = 0; i + 1 < (int) posOne.size(); i += 1) {
		for (int j = posOne[i + 1] - 1; j > posOne[i]; j -= 1)
			Remove(j);
		Remove(posOne[i + 1]);
	}
	for (int j = posOne.back() + 1; j < n; j += 1) {
		Remove(j);
	}
	Remove(x);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 780 KB Output is correct
2 Correct 0 ms 1032 KB Output is correct
3 Correct 0 ms 792 KB Output is correct
4 Correct 0 ms 792 KB Output is correct
5 Correct 0 ms 788 KB Output is correct
6 Correct 0 ms 792 KB Output is correct
7 Correct 0 ms 792 KB Output is correct
8 Correct 0 ms 792 KB Output is correct
9 Correct 0 ms 792 KB Output is correct
10 Correct 1 ms 780 KB Output is correct
11 Correct 0 ms 780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 8332 KB Output is correct
2 Correct 37 ms 8144 KB Output is correct
3 Incorrect 40 ms 8124 KB Wrong Answer [6]
4 Halted 0 ms 0 KB -