Submission #507641

#TimeUsernameProblemLanguageResultExecution timeMemory
507641sliviuPaint By Numbers (IOI16_paint)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;

string solve_puzzle(string s, const vector<int>& c) {
	string ans = "";
	int n = s.length(), k = c.size();
	s = '$' + s;
	vector<int> canw(n + 2), canb(n + 2), cnt(n + 1);
	vector<vector<int>> dpb(n + 2, vector<int>(k + 2)), dpa(n + 2, vector<int>(k + 2));
	for (int i = 1; i <= n + 1; ++i)
		cnt[i] = cnt[i - 1] + (s[i] == '_');
	dpb[0][0] = dpa[n + 1][k] = 1;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j <= k; ++j) {
			if (s[i + 1] != 'X')
				dpb[i + 1][j] |= dpb[i][j];
			if (j < k&& i + c[j] + 1 <= n && s[i + c[j] + 1] != 'X' && cnt[i] == cnt[i + c[j]])
				dpb[i + c[j] + 1][j + 1] |= dpb[i][j];
		}

	for (int i = n + 1; i > 1; --i)
		for (int j = 0; j <= k; ++j) {
			if (s[i - 1] != 'X')
				dpa[i - 1][j] |= dpa[i][j];
			if (j && i - c[j - 1] - 1 >= 1 && s[i - c[j - 1] - 1] != 'X' && cnt[i] == cnt[i - c[j - 1]])
				dpa[i - c[j - 1] - 1][j - 1] |= dpa[i][j];
		}

	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= k; ++j) {
			if (s[i] != 'X' && dpb[i][j] && dpa[i][j])
				canw[i] |= 1;
			if (j < k && i + c[j] <= n && dpb[i][j] && dpa[i + c[j] + 1][j + 1] && cnt[i] == cnt[i + c[j]])
				++canb[i + 1], --canb[i + c[j] + 1];
		}
	for (int i = 1; i <= n; ++i) {
		canb[i] += canb[i - 1];
		if (canw[i] && canb[i])
			ans += '?';
		else
			ans += (canw[i] ? '_' : 'X');
	}
	cout << ans << " | ";
	return ans;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccUFfeOc.o: in function `main':
grader.cpp:(.text.startup+0x213): undefined reference to `solve_puzzle(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status