Submission #837162

# Submission time Handle Problem Language Result Execution time Memory
837162 2023-08-25T05:36:52 Z pavement Parrots (IOI11_parrots) C++17
0 / 100
2000 ms 12008 KB
#include "encoder.h"
#include "encoderlib.h"
#include <bitset>
#include <cassert>
#include <iostream>
#include <array>
using namespace std;

const int LEN = 514, LIM = 517, K = 261;

static bitset<LEN> operator+ (const bitset<LEN> &lhs, const bitset<LEN> &rhs) {
	bitset<LEN> res;
	res.reset();
	bool carry = 0;
	for (int i = 0; i < LEN; i++) {
		res[i] = carry ^ lhs[i] ^ rhs[i];
		if ((carry && lhs[i]) || (carry && rhs[i]) || (lhs[i] && rhs[i])) {
			carry = 1;
		} else {
			carry = 0;
		}
	}
	assert(carry == 0);
	return res;
}

static bool fullSubtractor(bool b1, bool b2, bool& borrow) {
	bool diff;
	if (borrow) {
		diff = !(b1 ^ b2);
		borrow = !b1 || (b1 && b2);
	}
	else {
		diff = b1 ^ b2;
		borrow = !b1 && b2;
	}
	return diff;
}

static bitset<LEN> operator- (const bitset<LEN> &lhs, const bitset<LEN> &rhs) {
	bool borrow = 0;
	bitset<LEN> ans;
	for (int i = 0; i < LEN; i++) {
		ans[i] = fullSubtractor(lhs[i], rhs[i], borrow);
	}
	return ans;
}

static bitset<LEN> nck[LIM][LIM];

static void precompute_binomials() {
	for (int i = 0; i < LIM; i++) {
		for (int j = 0; j <= i; j++) {
			if (i == 0 || j == 0) {
				nck[i][j] = j == 0;
			} else {
				nck[i][j] = nck[i - 1][j] + nck[i - 1][j - 1];
			}
		}
	}
}

void encode(int N, int M[]) {
	precompute_binomials();
	bitset<LEN> cur;
	cur.reset();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 8; j++) {
			cur[i * 8 + j] = !!(M[i] & (1 << j));
		}
	}
	for (int i = 0, val = 0; i < K; i++) {
		while (1) {
			int len_left = K - 1 - i;
			int vals_left = 256 - val;
			if (nck[len_left + vals_left][vals_left].to_string() <= cur.to_string()) {
				cur = cur - nck[len_left + vals_left][vals_left];
				val++;
			} else {
				break;
			}
		}
		send(val);
	}
}
#include "decoder.h"
#include "decoderlib.h"
#include <bitset>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <array>
using namespace std;

int A[105];

const int LEN = 514, LIM = 517, K = 261;

static bitset<LEN> operator+ (const bitset<LEN> &lhs, const bitset<LEN> &rhs) {
	bitset<LEN> res;
	res.reset();
	bool carry = 0;
	for (int i = 0; i < LEN; i++) {
		res[i] = carry ^ lhs[i] ^ rhs[i];
		if ((carry && lhs[i]) || (carry && rhs[i]) || (lhs[i] && rhs[i])) {
			carry = 1;
		} else {
			carry = 0;
		}
	}
	assert(carry == 0);
	return res;
}

static bool fullSubtractor(bool b1, bool b2, bool& borrow) {
	bool diff;
	if (borrow) {
		diff = !(b1 ^ b2);
		borrow = !b1 || (b1 && b2);
	}
	else {
		diff = b1 ^ b2;
		borrow = !b1 && b2;
	}
	return diff;
}

static bitset<LEN> operator- (const bitset<LEN> &lhs, const bitset<LEN> &rhs) {
	bool borrow = 0;
	bitset<LEN> ans;
	for (int i = 0; i < LEN; i++) {
		ans[i] = fullSubtractor(lhs[i], rhs[i], borrow);
	}
	return ans;
}

static bitset<LEN> nck[LIM][LIM];

static void precompute_binomials() {
	for (int i = 0; i < LIM; i++) {
		for (int j = 0; j <= i; j++) {
			if (i == 0 || j == 0) {
				nck[i][j] = j == 0;
			} else {
				nck[i][j] = nck[i - 1][j] + nck[i - 1][j - 1];
			}
		}
	}
}

void decode(int N, int L, int X[]) {
	precompute_binomials();
	sort(X, X + L);
	bitset<LEN> num(0);
	for (int i = 0; i < L; i++) {
		int len_left = L - i - 1;
		for (int val = i ? X[i - 1] : 0; val < X[i]; val++) {
			int val_left = 256 - val;
			num = num + nck[len_left + val_left][val_left];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 8; j++) {
			if (num[i * 8 + j]) {
				A[i] |= (1 << j);
			}
		}
		output(A[i]);
	}
}

Compilation message

decoder.cpp:43:20: warning: 'std::bitset<514> operator-(const std::bitset<514>&, const std::bitset<514>&)' defined but not used [-Wunused-function]
   43 | static bitset<LEN> operator- (const bitset<LEN> &lhs, const bitset<LEN> &rhs) {
      |                    ^~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 243 ms 11844 KB Error : Encoded message too long
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 224 ms 11900 KB Error : Encoded message too long
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 218 ms 11852 KB Error : Encoded message too long
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 220 ms 11892 KB Error : Encoded message too long
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 219 ms 11912 KB Error : Encoded message too long
2 Incorrect 443 ms 11916 KB Error : Bad encoded integer
3 Incorrect 1969 ms 11936 KB Error : Bad encoded integer
4 Execution timed out 2057 ms 11888 KB Time limit exceeded
5 Execution timed out 2019 ms 11884 KB Time limit exceeded
6 Incorrect 439 ms 11988 KB Error : Bad encoded integer
7 Incorrect 1529 ms 12008 KB Error : Bad encoded integer