Submission #861790

# Submission time Handle Problem Language Result Execution time Memory
861790 2023-10-17T03:04:07 Z maks007 parentrises (BOI18_parentrises) C++14
5 / 100
1000 ms 428 KB
#include "bits/stdc++.h"

using namespace std;

string str;
vector <int> rgb, ans;
int f;

void do_1() {
	if(rgb.size() == str.size()) {
		int balb = 0, balr = 0;
		for(int i = 0; i < str.size(); i ++) {
			if(str[i] == '(') {
				if(rgb[i] == 0) balb ++;
				else if(rgb[i] == 1) balr ++;
				else balb ++, balr ++;
			}else {
				if(rgb[i] == 0) balb --;
				else if(rgb[i] == 1) balr --;
				else balb --, balr --;
				if(min(balb, balr) < 0) goto end;
			}
		}
		if(balr == 0 && balb == 0) {
			ans = rgb;
			f = 1;
		}
		return;
		end:;
		return;
	}
	for(int i = 0; i < 3; i ++) {
		rgb.push_back(i);
		do_1();
		rgb.pop_back();
		if(f) return;
	}
}

signed main () {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int T, q;
	cin >> T >> q;
	while(q --) {
		cin >> str;
		if(T == 1) {
			f = 0;
			do_1();
			if(!f) {
				cout << "impossible\n";
				continue;
			}
			for(auto i : ans) {
				if(i == 0) cout << "B";
				else if(i == 1) cout << "R";
				else cout << "G";
			}
			cout << "\n";
		}else {
			// cout << ans;
		}
	}
	return 0;
}

Compilation message

parentrises.cpp: In function 'void do_1()':
parentrises.cpp:12:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |   for(int i = 0; i < str.size(); i ++) {
      |                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 23 ms 348 KB Output is correct
5 Correct 127 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1055 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1055 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1055 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -