이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// And you curse yourself for things you never done
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 310, maxn2 = 1e6 + 10, mod = 1e9 + 7;
int dp[maxn][2 * maxn][maxn]; // n // 2o - c // o - 2c
int ans[maxn];
void add(int &A, int B){
A = (A + B) % mod;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();
int P, q;
cin >> P >> q;
if(P == 1){
while(q--){
string s;
cin >> s;
int A = 0;
bool bad = 0;
for(int i = sz(s)-1; i >= 0; i--){
A+= (s[i] == ')' ? 2 : -1);
bad|= A < 0;
}
A = 0;
for(int i = 0; i < sz(s); i++){
A+= (s[i] == '(' ? 2 : -1);
bad|= A < 0;
}
if(bad){
cout << "impossible\n";
continue;
}
int pos = sz(s) - A;
string ans = s;
bool o = 0;
for(int i = 0; i < pos; i++){
if(s[i] == '(')
ans[i] = 'G';
else
ans[i] = (o ? 'R' : 'B'), o^=1;
}
o = 0;
for(int i = sz(s)-1; i >= pos; i--){
if(s[i] == ')')
ans[i] = 'G';
else
ans[i] = (o ? 'R' : 'B'), o^=1;
}
cout << ans << "\n";
}
}
if(P == 2){
dp[0][0][0] = 1;
for(int n = 0; n < maxn - 5; n++){
for(int sm = 0; sm <= 2 * n; sm++){
for(int mx = 0; mx <= n; mx++){
add(dp[n + 1][sm + 2][max(int(0), mx + 1)], dp[n][sm][mx]);
if(sm > 0)
add(dp[n+1][sm - 1][max(int(0), mx - 2)], dp[n][sm][mx]);
}
add(ans[n], dp[n][sm][0]);
}
}
while(q--){
int n;
cin >> n;
cout << ans[n] << "\n";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |