1823D - Unique Palindromes - CodeForces Solution


constructive algorithms math strings *1900

Please click on ads to support us..

C++ Code:

//#pragma GCC optimize ("O3")

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> x(k + 1), c(k + 1);
	for (int i{1}; i <= k; ++i) cin >> x[i];
	for (int i{1}; i <= k; ++i) cin >> c[i];

	vector<char> ans(n);
	char abc{'a'};
	ans[0] = 'a', ans[1] = 'b', ans[2] = 'c';
	x[0] = 3, c[0] = 3;

	for (int i{1}; i <= k; ++i) {
		if (x[i] - x[i - 1] < c[i] - c[i - 1]) return cout << "NO\n", []{}();
		int i2{x[i - 1] + c[i] - c[i - 1]};
		for (int j{x[i - 1]}; j < i2; ++j) ans[j] = 'c' + i;
		for (int j{i2}; j < x[i]; ++j) ans[j] = abc, abc = (abc == 'c' ? 'a' : abc + 1);
	}

	cout << "YES\n";
	for (int i{0}; i < n; ++i) cout << ans[i];
	cout << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t{1};
	cin >> t;
	while (t--) solve();
}


Comments

Submit
0 Comments
More Questions

1607A - Linear Keyboard
EQUALCOIN Equal Coins
XOREQN Xor Equation
MAKEPAL Weird Palindrome Making
HILLSEQ Hill Sequence
MAXBRIDGE Maximise the bridges
WLDRPL Wildcard Replacement
1221. Split a String in Balanced Strings
1002. Find Common Characters
1602A - Two Subsequences
1555A - PizzaForces
1607B - Odd Grasshopper
1084A - The Fair Nut and Elevator
1440B - Sum of Medians
1032A - Kitchen Utensils
1501B - Napoleon Cake
1584B - Coloring Rectangles
1562B - Scenes From a Memory
1521A - Nastia and Nearly Good Numbers
208. Implement Trie
1605B - Reverse Sort
1607C - Minimum Extraction
1604B - XOR Specia-LIS-t
1606B - Update Files
1598B - Groups
1602B - Divine Array
1594B - Special Numbers
1614A - Divan and a Store
2085. Count Common Words With One Occurrence
2089. Find Target Indices After Sorting Array