AT AGC052A Long Common Subsequence 题解

Link

小清新构造题,没什么思路的时候不妨重读题面手模一下。注意到,这三个字符串中都含有 \(n\)\(1\)\(n\)\(0\)。从子序列的角度入手,是很容易想到不关心具体顺序开桶计次数直接丢进答案里类似的思路的。具体地对于这个题,我们构造方式如下:

\[\overline{n \times 0} + \overline{n \times 1} + 0 \]

类似地,也可以构造 \(1\dots1 + 0 \dots 0 + 1\) 这样的序列。感性理解一下,我们先挑出来的这 \(n\) 个数和下一个自身之间的距离都是 \(n\) 的,中间必然有 \(n\) 的距离被另一种数填充,最后甩上任意一个数满足 \(2n + 1\) 的长度限制就做完了。

#include <bits/stdc++.h>

using i64 = long long;

void solve() {
	int n;
	std::cin >> n;
	std::string s1, s2, s3;
	std::cin >> s1 >> s2 >> s3;
	for (int i = 1; i <= n; i++)
		std::cout << "0";
	for (int i = 1; i <= n; i++)
		std::cout << "1";
	std::cout << "0\n";
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int t;
	std::cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}
posted @ 2025-11-06 09:10  夢回路  阅读(9)  评论(0)    收藏  举报