QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#864592#5018. nthduongnc000100 ✓31ms19984kbC++234.2kb2025-01-20 19:41:382025-01-20 19:41:49

Judging History

你现在查看的是最新测评结果

  • [2025-01-20 19:41:49]
  • 评测
  • 测评结果:100
  • 用时:31ms
  • 内存:19984kb
  • [2025-01-20 19:41:38]
  • 提交

answer

#include "nth.h"
#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define isz(x) (int)x.size()
using namespace std;

#define lm (l + (r - l - 1) / 2)
#define rm (l + (r - l) / 2)
#define pl pfx
#define pr (pfx + (1 << (bit + 1)) - 1)

namespace Alice {
	vector<int> A;
	int l, r, c, bit = 20, pfx = 0, lst;

	int getlen() { return r - l; }

	int getvalue(int val) { return (val < pl ? pl : (val > pr ? pr : val)); }

	void initA(std::bitset<M> _A, unsigned S, unsigned _c) {
		c = _c - 1;
		// cout << "A: ";
		for (int i = 0; i < M; ++i) if (_A.test(i)) {
			// cout << i << " ";
			A.emplace_back(i);
		}
		// cout << endl;

		int cntA = isz(A), cntB = S - cntA;
		if (c < min(cntA, cntB)) {
			l = 0, r = c + 1, c = 0;
		}
		else if (cntA <= c and c < cntB) {
			A.insert(A.begin(), 0);
			l = 0, r = cntA + 1, c = 1;
		}
		else if (cntB <= c and c < cntA) {
			l = c - cntB, r = c + 1, c = 1;
		}
		else {
			l = c - cntB, r = cntA, c = 1;
		}

		// cout << "A: ";
		// for (int i = l; i < r; ++i) {
		// 	cout << A[i] << " \n"[i + 1 == r];
		// }

		if (r - l == 1) {
			for (int i = 20; i >= 0; --i) {
				sendA(A[l] >> i & 1);
			}
			return;
		}
		if (r - l == 2) {
			for (int i = l; i < r; ++i) for (int j = bit; j >= 0; --j) {
				// cout << (getvalue(A[i]) >> j & 1);
				// if (j == 0) cout << endl;
				sendA(getvalue(A[i]) >> j & 1);
			}
			return;
		}

		sendA(lst = (getvalue(A[lm]) >> bit & 1));
	}

	void receiveA(bool x) {
		// cout << "rA: " << x << endl;
		if (lst == x) {
			pfx += lst << bit;
			--bit;
		}
		else if (lst and not x) {
			r = lm + 1;
			// cout << "nA: " << l << " " << r << endl;
		}
		else {
			l = lm;
			// cout << "nA: " << l << " " << r << endl;
		}
		if (r - l == 2) {
			for (int i = l; i < r; ++i) for (int j = bit; j >= 0; --j) {
				// cout << (getvalue(A[i]) >> j & 1);
				// if (j == 0) cout << endl;
				sendA(getvalue(A[i]) >> j & 1);
			}
			return;
		}
		sendA(lst = (getvalue(A[lm]) >> bit & 1));
	}
}

namespace Bob {
	vector<int> B, res;
	int l, r, c, bit = 20, pfx = 0, lst, cnt1 = 0, Aval = 0;

	int getlen() { return r - l; }

	int getvalue(int val) { return (val < pl ? pl : (val > pr ? pr : val)); }

	void initB(std::bitset<M> _B, unsigned S, unsigned _c) {
		c = _c - 1;
		// cout << "B: ";
		for (int i = 0; i < M; ++i) if (_B.test(i)) {
			// cout << i << " ";
			B.emplace_back(i);
		}
		// cout << endl;

		int cntB = isz(B), cntA = S - cntB;
		if (c < min(cntB, cntA)) {
			l = 0, r = c + 1, c = 0;
		}
		else if (cntB <= c and c < cntA) {
			B.insert(B.begin(), 0);
			l = 0, r = cntB + 1, c = 1;
		}
		else if (cntA <= c and c < cntB) {
			l = c - cntA, r = c + 1, c = 1;
		}
		else {
			l = c - cntA, r = cntB, c = 1;
		}

		// cout << "B: ";
		// for (int i = l; i < r; ++i) {
		// 	cout << B[i] << " \n"[i + 1 == r];
		// }

	}

	void receiveB(bool x) {
		if (r - l == 1) {
			Aval = Aval << 1 | ((int)x);
			if (++cnt1 == 21) {
				vector<int> res = {Aval, B[l]};
				sort(all(res)); report(res[c]);
			}
			return;
		}
		if (r - l == 2) {
			// cout << cnt1 << " " << bit << " " << x << endl;
			if (cnt1 == 0 or cnt1 == bit + 1) {
				res.emplace_back(0);
			}

			if (cnt1 < bit + 1) {
				res.back() = res.back() << 1 | ((int)x);
				++cnt1;
			}
			else {
				res.back() = res.back() << 1 | ((int)x);
				++cnt1;
			}

			// cout << isz(res) << endl;
			if (cnt1 == 2 * (bit + 1)) {
				// cout << res[0] << " " << res[1] << endl;
				res[0] += pfx, res[1] += pfx;
				res.emplace_back(getvalue(B[l]));
				res.emplace_back(getvalue(B[l + 1]));
				sort(all(res));
				// for (auto val : res) cout << val << " ";
				// cout << endl;
				res.pop_back(); res.erase(res.begin());
				report(res[c]);
			}
			return;
		}
		// cout << "rB: " << x << endl;
		sendB(lst = (getvalue(B[rm]) >> bit & 1));
		if (lst == x) {
			pfx += lst << bit;
			if (--bit == -1) report(pfx);
		}
		else if (lst and not x) {
			r = rm + 1;
			// cout << "nB: " << l << " " << r << endl;
		}
		else {
			l = rm;
			// cout << "nB: " << l << " " << r << endl;
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 100
Accepted

Test #1:

score: 100
Accepted
time: 29ms
memory: 19984kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

3196614622 1083345 21

result:

points 1.0 OK L = 21

Test #2:

score: 100
Accepted
time: 31ms
memory: 13764kb

input:

111111100101001001100100000000111110101000101001001100101010011110000110101011010000000001000111000001011011110101010111001101010000101001101011101001110011001001101111110100001111001001010000110000011011000101010010000000011010010111110000111011011100110000100101111000111111110001100110110111101001...

output:

4153393124 307591 21

result:

points 1.0 OK L = 21

Test #3:

score: 100
Accepted
time: 29ms
memory: 15204kb

input:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

1444424234 522975 42

result:

points 1.0 OK L = 42

Test #4:

score: 100
Accepted
time: 28ms
memory: 17220kb

input:

001101001011011011110001100111001010010100110110111111100011101010001111110101110101110011111001110110111010001100100011010101011000000000001010010001011111110101111100000101000010101110100000110101010100100100010010110010010000001010010100110110100101111110010011011111011111110010100010001110110011...

output:

3619264599 491607 42

result:

points 1.0 OK L = 42

Test #5:

score: 100
Accepted
time: 15ms
memory: 11692kb

input:

111111100110100111101001011010001100010101010010010110010010101011100111110111101101011110111100011001100010111011001000101000111000000000001010110001111010001110110100111110101011000001110000010100111010001110110111000001010101010001110110100111110011111001001101000011101010111010111001100010010000...

output:

2453620143 222311 70

result:

points 1.0 OK L = 70

Test #6:

score: 100
Accepted
time: 16ms
memory: 11176kb

input:

010000110010100010000100101100000101110100111110011000000010000000110000001010010010110100011101010001101010010110000011000000010000000110010010001011010101111111100001110101010101000011100111100011100001001011001011011000100000101101010101111011111011010110011101010011000101000011110100010101110100...

output:

3106575258 96616 76

result:

points 1.0 OK L = 76

Test #7:

score: 100
Accepted
time: 16ms
memory: 11160kb

input:

000010111100100011010101110011011100111000111011001101010101110001011011111000111000111011111101011010111100100011111101110001110000011011100010001000001100000101110011001100101110010000111110100101100010100000111010001000001010011000110111100101011011111101000011010000110100000100011110101001110000...

output:

231451419 44869 72

result:

points 1.0 OK L = 72

Test #8:

score: 100
Accepted
time: 16ms
memory: 10548kb

input:

110011000011011100100010011110111101101010001101101000011011010110111100010011001001101010100110010110011001001110110000111000011101100011101111101111011001111000011000001110101001101001100000000001111100000011010110100000000110011010100100100011001001000000111001100001011010110000101111000000000100...

output:

2146141025 203865 74

result:

points 1.0 OK L = 74

Test #9:

score: 100
Accepted
time: 13ms
memory: 10760kb

input:

010111110100110001011110101111110010110010010000101010001011101000100000101010101000010100111110111101101010111111110101010101110010101000101100100001100001001110011111011010100110001001010000100010101001110010110000001010010011100111000001011110101100101011010100111111101100000000000100011111100111...

output:

1530939132 71635 74

result:

points 1.0 OK L = 74

Test #10:

score: 100
Accepted
time: 14ms
memory: 11952kb

input:

100000000010111111001011011000101110100100110110100000000100010011001111110000000110001110000111010110001010011110010110101111000000101010001001001111100110001101000111010100100111000000011000100111000011101110100111111001111001101111100011101011010010111101101101010011001001101100110001011010101110...

output:

3917079713 66212 72

result:

points 1.0 OK L = 72

Test #11:

score: 100
Accepted
time: 16ms
memory: 11896kb

input:

110011101110110111110100111011101011110000110011010100010100111110001111111001011111110111000010111001110011110011011100100100000001010001000111000010100110011111101010000000100000100100110101001110100001101011110010011001001110110110000001111000111100000110000110101111001001001001101100001100100010...

output:

1969203498 32471 62

result:

points 1.0 OK L = 62

Test #12:

score: 100
Accepted
time: 14ms
memory: 11160kb

input:

000111001100010010000011011000010111000010000110111110011011001001011011000001001110001011101001101000110010111010111000111000011001001000111100100001000000111101101000111000001111011100011111000010000110011101111001110000100100000010101001101000110010011011110110011100101101110000101111010100110000...

output:

314678533 150418 66

result:

points 1.0 OK L = 66

Test #13:

score: 100
Accepted
time: 16ms
memory: 10204kb

input:

001110001000001101001010011100101100011110101100100110000110110000111011111110111010001101011011110010010000010010001001100011000101010110000111110111100111101100011001100001011000100111011100100100011000011001100000100111010001011110011100110011110111011010100011010011101100110010101001011101000000...

output:

3420667525 43478 72

result:

points 1.0 OK L = 72

Test #14:

score: 100
Accepted
time: 16ms
memory: 11468kb

input:

000010101110000110100010111001000010010110110111100101001010010011000000101000011010101100011101010101010100100100000100110011110011100110001111011111111001101100000010010111101101000101110100100111000000011010101001100001010000001100001110111111000111001101111101011011001110011011100100101001100100...

output:

313408403 219687 74

result:

points 1.0 OK L = 74

Test #15:

score: 100
Accepted
time: 12ms
memory: 11664kb

input:

110000101111011000011000101011000001101100100101011110011110110111100101100000011110011001000001000101100000101100100011111010111011000111001111001010011011111001111111001000001010101000110011010001111011100100100011110010001000101100001001010000100011100001101001001101111010101111111100001110010100...

output:

2777622505 129823 76

result:

points 1.0 OK L = 76

Test #16:

score: 100
Accepted
time: 16ms
memory: 10848kb

input:

101110101011011001010011010100101111011100110000011011101001111001111000001111011000101110011001010110100111100001001010010000001011001111101001011000111000110100000100000011101010011111101000101010000010001011001101000110000010101011000000101000110011010111010110011110101101110010001010000011000000...

output:

1604023773 173204 76

result:

points 1.0 OK L = 76

Test #17:

score: 100
Accepted
time: 17ms
memory: 11040kb

input:

101100010100110001101001101000011011001101100100010111010100111001000000100010111101011100001100000011010011000101010000111101001011110000000110010100100111011111010011111011110011111110001010110011100000111110001011011010111000100001001001111110110000000110111010101100111000100011111101000010001100...

output:

1162653421 98067 68

result:

points 1.0 OK L = 68

Test #18:

score: 100
Accepted
time: 14ms
memory: 11484kb

input:

100111111011101111011011000101000011011001100000111001000101100110101001011001111110011100101001100001101111101101010110110111100100110011100111110101101111101110101101010011100010001000010011010111001011100001001011000101101110000001001111010011110010110011001100101101101100110010010110011011010011...

output:

2853070317 247143 70

result:

points 1.0 OK L = 70

Test #19:

score: 100
Accepted
time: 18ms
memory: 10552kb

input:

110111100111100111001111101001110111000000101001011001101111010110000010000100000011111000000111011110010010100111000000001110001001100001000111101010010100101111011011100100001000100111001011110001010010111101001110111101000010010010010010011111001111110111100001001100110100111100000100100101001100...

output:

1170245885 93479 70

result:

points 1.0 OK L = 70

Test #20:

score: 100
Accepted
time: 17ms
memory: 10316kb

input:

010100100000001101011100100011100011001010011011011001011100000110000111100001110100011101011000000110111010101101000100010110100010010110001110101111110111000000001100100010100100111000000110100000001111001100111011111011110010000100100000110101111111010111011110100111011101001110100100111100111110...

output:

1138672942 140644 70

result:

points 1.0 OK L = 70