답안 #861851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
861851 2023-10-17T05:03:43 Z iskhakkutbilim parentrises (BOI18_parentrises) C++17
16 / 100
127 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int mod = 1e9 + 7;

int P;

void solve(){
	string s; cin >> s;
	int n = s.size();
	map<pair<int, int>, bool> dp[n];
	string path[n][n + 1][n + 1];	
	vector<vector<pair<int, int> >> parent(n, vector<pair<int, int> >(3, {-1, -1}));
	// RBG
	if(s[0] == ')' or s[n-1] == '('){
		cout << "impossible";
		return;
	}
	dp[0][{0, 1}] = 1, dp[0][{1, 0}] = 1;
	dp[0][{1, 1}] = 1;
	path[0][0][1] = "R";
	path[0][1][1] = "G";
	path[0][1][0] = "B";
	for(int i = 1;i < n; i++){
		for(auto [pp, y] : dp[i-1]){
			int x1 = pp.ff, x2 = pp.ss;
			if(!y) assert(false);
			int ok = 0;
			int c = s[i]==')' ? -1 : 1;
			if(x2 + c >= 0){
				ok++;
				dp[i][{x1, x2 + c}] = 1;
				path[i][x1][x2 + c] = path[i-1][x1][x2] + "R";
			}
			if(x1 + c >= 0){
				ok++;
				dp[i][{x1 + c, x2}] = 1;	
				path[i][x1 + c][x2] = path[i-1][x1][x2] + "B";
			}
			if(ok == 2){
				dp[i][{x1 + c, x2 + c}] = 1;	
				path[i][x1 + c][x2 + c] = path[i-1][x1][x2] + "G";
			}
		}
	}
	if(dp[n-1][{0, 0}]){
		cout << path[n-1][0][0];
	}else{
		cout << "impossible";
	}
}


main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   cin >> P;
	int test; cin >> test;
	while(test--){
		solve();
		cout << '\n';
	}
	return 0;
}

Compilation message

parentrises.cpp:57:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   57 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16732 KB Output is correct
2 Correct 52 ms 46824 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 5 ms 5468 KB Output is correct
5 Correct 42 ms 42752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16732 KB Output is correct
2 Correct 52 ms 46824 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 5 ms 5468 KB Output is correct
5 Correct 42 ms 42752 KB Output is correct
6 Runtime error 127 ms 262144 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16732 KB Output is correct
2 Correct 52 ms 46824 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 5 ms 5468 KB Output is correct
5 Correct 42 ms 42752 KB Output is correct
6 Runtime error 127 ms 262144 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Expected integer, but "impossible" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Expected integer, but "impossible" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Expected integer, but "impossible" found
2 Halted 0 ms 0 KB -