Submission #61968

# Submission time Handle Problem Language Result Execution time Memory
61968 2018-07-27T07:01:23 Z koosaga(#1793) parentrises (BOI18_parentrises) C++11
0 / 100
3 ms 740 KB
#include<bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
using lint = long long;
const int MAXN = 1000050;
 
bool Do(string s, string cert){
	int c0 = 0, c1 = 0;
	for(int i=0; i<s.size(); i++){
		if(s[i] == '('){
			if(cert[i] != 'B') c0++;
			if(cert[i] != 'R') c1++;
		}
		else{
			if(cert[i] != 'B') c0--;
			if(cert[i] != 'R') c1--;
			if(c0 < 0 || c1 < 0) return 0;
		}
	}
	if(c0 == 0 && c1 == 0) return 1;
	return 0;
}
string solve(string s){
	queue<int> que;
	string chk;
	chk.resize(s.size());
	int cnt = 0, r = 0, b = 0;
	for(int i=0; i<s.size(); i++){
		if(s[i] == '('){
			que.push(i);
			cnt++;
			if(r <= b) chk[i] = 'R', r++;
			else chk[i] = 'B', b++;
		}
		else{
			if(r >= b && r > 0) chk[i] = 'R', r--;
			else if(b > 0) chk[i] = 'B', b--;
			else{
				if(que.empty()) return "impossible";
				int x = que.front();
				que.pop();
				if(chk[x] == 'R'){
					chk[x] = 'G';
					chk[i] = 'B';
				}
				else{
					chk[x] = 'G';
					chk[i] = 'R';
				}
			}
		}
	}
	for(int i=(int)s.size()-1; i>=0; i--){
		if(s[i] == ')' && chk[i] == 'B' && r){
			chk[i] = 'G';
			r--;
		}
		if(s[i] == ')' && chk[i] == 'R' && b){
			chk[i] = 'G';
			b--;
		}
	}
	assert(Do(s, chk));
	return chk;
}
 
int f(int x){ return x; }
int main(){
	char buf[MAXN];
	int p, t; cin >> p;
	if(p == 1){
		scanf("%d",&t);
		while(t--){
			scanf("%s",buf);
			string ans = buf;
			printf("%s\n", solve(buf).c_str());
		}
	}
	else{
		scanf("%d",&t);
		while(t--){
			int n; cin >> n;
			cout << f(n) << endl;
		}
	}
}

Compilation message

parentrises.cpp: In function 'bool Do(std::__cxx11::string, std::__cxx11::string)':
parentrises.cpp:9:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<s.size(); i++){
               ~^~~~~~~~~
parentrises.cpp: In function 'std::__cxx11::string solve(std::__cxx11::string)':
parentrises.cpp:28:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<s.size(); i++){
               ~^~~~~~~~~
parentrises.cpp: In function 'int main()':
parentrises.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&t);
   ~~~~~^~~~~~~~~
parentrises.cpp:74:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%s",buf);
    ~~~~~^~~~~~~~~~
parentrises.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&t);
   ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Runtime error 3 ms 740 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 740 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 740 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 740 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 740 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 740 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 740 KB Output isn't correct