Submission #59745

# Submission time Handle Problem Language Result Execution time Memory
59745 2018-07-23T03:42:48 Z model_code parentrises (BOI18_parentrises) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

string solve(const string &test) {
	const int N = test.size();
	assert(1 <= N && N <= NMAX);

	string  redMask(N, ' ');
	string blueMask(N, ' ');

	vector <int> redStk;
	queue <int> redOpened;
	for (int i = 0; i < N; ++ i) {
		const char ch = test[i];
		if (ch == '(') {
			redMask[i] = 'R';
			redStk.push_back(i);
			redOpened.push(i);
		}
		else if (ch == ')') {
			if (!redStk.empty()) {
				redMask[i] = 'R';
				redStk.pop_back();
			}
			else if (redOpened.empty())
				return "impossible";
			else {
				blueMask[i] = 'B';
				blueMask[redOpened.front()] = 'B';
				redOpened.pop();
			}
		}
	}

	reverse(redStk.begin(), redStk.end());
	stack <int> redClosed;

	int i = N - 1;
	for (const int pos: redStk) {
		while (i > pos) {
			if (test[i] == ')')
				redClosed.push(i);
			-- i;
		}
		if (redClosed.empty())
			return "impossible";
		else {
			redMask[pos]  = ' ';
			blueMask[pos] = 'B';

			const int transformToGreen = redClosed.top();
			redClosed.pop();
			blueMask[transformToGreen] = 'B';
		}
	}

	string coloring;
	for (i = 0; i < N; ++ i)
		if (redMask[i] == 'R' && blueMask[i] == 'B')
			coloring += 'G';
		else if (redMask[i] == 'R')
			coloring += 'R';
		else if (blueMask[i] == 'B')
			coloring += 'B';
		else
			assert(0);
	return coloring;
}

int main() {
	int type; cin >> type;
	if (type == 2) {
            return 0;
        }

	int T;
	cin >> T;
	while (T --) {
		// Read test
		string str;
		cin >> str;
		
		// Check validity
		assert(1 <= str.size() && str.size() <= 1000000);
		for (auto it: str)
			assert(it == '(' || it == ')');
		cout << solve(str) << '\n';
	}
	return 0;
}

Compilation message

In file included from /usr/include/c++/7/cassert:44:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from parentrises.cpp:1:
parentrises.cpp: In function 'std::__cxx11::string solve(const string&)':
parentrises.cpp:7:24: error: 'NMAX' was not declared in this scope
  assert(1 <= N && N <= NMAX);
                        ^
parentrises.cpp:7:24: note: suggested alternative: 'NAN'