QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#405711#5874. Mystery Square5ab41 ✓5512ms3776kbC++203.0kb2024-05-06 12:53:412024-05-06 12:53:42

Judging History

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

  • [2024-05-06 12:53:42]
  • 评测
  • 测评结果:41
  • 用时:5512ms
  • 内存:3776kb
  • [2024-05-06 12:53:41]
  • 提交

answer

/* name: grow
 * author: 5ab
 * created at: 2024-05-06
 */
#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define ssz(x) (int((x).size()))

auto chmax = [](auto& x, auto y) { if (x < y) x = y; };
auto chmin = [](auto& x, auto y) { if (y < x) x = y; };

using ll = unsigned long long;
const int N = 125, QC = 40, L = 18;

__int128 stoi128(string s)
{
	__int128 x = 0;
	for (char c : s)
		x = x * 2 + (c - '0');
	return x;
}
string itos128(__int128 x)
{
	return (x >= 2 ? itos128(x / 2) : ""s) + "01"[x % 2];
}

string ans;
bool solve(string s)
{
	int n = ssz(s), m = (n + 1) / 2, sc = 0;
	
	for (int i = 0; i < m; i++)
		sc += s[i] == '?';
	string ss = s;
	auto chk = [&](const string& t) -> bool
	{
		if (ssz(ss) != ssz(t))
			return 0;
		for (int i = 0; i < n; i++)
			if (ss[i] != '?' && ss[i] != t[i])
				return 0;
		return 1;
	};
	if (sc <= L)
	{
		vector<int> qp;
		for (int i = 0; i < m; i++)
			if (s[i] == '?')
				qp.push_back(i);
		for (int i = 0; i < n; i++)
			if (s[i] == '?')
				s[i] = '0';
		int lim = (1 << sc);
		for (int i = 0; i < lim; i++)
		{
			for (int j = 0; j < sc; j++)
				s[qp[j]] = '0' + ((i >> j) & 1);
			auto l = stoi128(s);
			ll al = 0, ar = 1ll << m;
			while (al < ar)
			{
				ll mid = (al + ar) >> 1;
				if (__int128(mid) * mid < l)
					al = mid + 1;
				else
					ar = mid;
			}
			auto rs = __int128(al) * al;
			// assert(__int128(al + 1) * (al + 1) >= l + (1ll << rl));
			// cerr << itos128(rs) << " and\n" << itos128(l) << endl;
			auto ts = itos128(rs);
			if (chk(ts))
			{
				ans = ts;
				return 1;
			}
		}
	}
	else
	{
		assert(s.back() == '1');
		vector<int> qp;
		for (int i = m - 2; i < n; i++)
			if (s[i] == '?')
				qp.push_back(i);
		for (int i = 0; i < n; i++)
			if (s[i] == '?')
				s[i] = '0';
		int lim = (1 << ssz(qp));
		// cerr << ssz(qp) << " " << lim << endl;
		for (int i = 0; i < lim; i++)
		{
			for (int j = 0; j < ssz(qp); j++)
				s[qp[j]] = '0' + ((i >> j) & 1);
			auto l = stoi128(s);
			for (__int128 c : {1, 3})
			{
				// cerr << i << " " << itos128(l) << " " << s << endl;
				for (int j = 2; j < m; j++)
					c |= (((c * c) ^ l) & (1ll << (j + 1))) >> 1;
				auto rs = __int128(c) * c;
				auto ts = itos128(rs);
				// cerr << ts << " " << itos128(c) << endl;
				if (chk(ts))
				{
					ans = ts;
					return 1;
				}
			}
		}
	}
	return 0;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int cas;
	
	cin >> cas;
	for (int cid = 1; cid <= cas; cid++)
	{
		string s, ap;
		
		cin >> s;
		while (!s.empty())
		{
			if (s.back() == '1')
			{
				assert(solve(s));
				break;
			}
			if (s.back() == '?')
			{
				s.back() = '1';
				if (solve(s))
					break;
				s.back() = '0';
			}
			if (end(s)[-2] == '1')
				break;
			s.pop_back();
			s.pop_back();
			ap += "00";
		}
		cout << "Case #" << cid << ": " << ans + ap << endl;
	}
	
	return 0;
}
// started coding at: 05-06 10:05:09

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 30ms
memory: 3584kb

input:

25
1???
1
10??110??00??1000??
1??010?0110?1010?0?010?0111011?11100?100010?0??0??1
1??11????00??1?1?0?1??01??110110?11?00100110?00100?0?00
11?1?1???11111?11?1??11110000?00?????00??0?000?000?1
10??000000?0?00000?00000000??0?0000???00??????0000???
101???11??11000?????1??1?1??10??0?0100011?0001?01011001...

output:

Case #1: 1001
Case #2: 1
Case #3: 1011110110000100001
Case #4: 111010001100101000001010111011011100110001000110001
Case #5: 1101111110000101100101010111011001110010011000010000100
Case #6: 1111111111111111111111111000000000000000000000000001
Case #7: 1000000000000000000000000000000000000000000000000...

result:

ok 25 lines

Subtask #2:

score: 31
Accepted

Test #2:

score: 31
Accepted
time: 5512ms
memory: 3776kb

input:

25
1????????????????????111101010000011100110101111000001011111100110000011000101100000010010110100101000????????????????????
10?11100?000111??11?01010110100??1?100111?001000000??0101?110?0111?011?11?1??00010111?010??100?100??10?010?001001110111110?1
1000100111100100110011010111100001111010?????????...

output:

Case #1: 11100101110101010110111110101000001110011010111100000101111110011000001100010110000001001011010010100001101011000010100001
Case #2: 1011110000001110111001010110100001110011100010000001101010110001111011111110000010111101010100010010101010100100111011111001
Case #3: 1000100111100100110011010...

result:

ok 25 lines

Extra Test:

score: 0
Extra Test Passed