| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 63005 | hamzqq9 | parentrises (BOI18_parentrises) | C++14 | 62 ms | 1332 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define sz(x) (x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 1000500000
#define MOD 1000000007
#define N 305
#define LOG 20
using namespace std;
int p,t,x,n;
int cnt[2][N][N],res[N];
char s[1000006],col[1000006];
bool check() {
int lastbal=0,allbal=0;
for(int i=1;i<=n;i++) {
if(s[i]=='(') {
allbal++;
lastbal++;
}
else {
lastbal=max(0,lastbal-2);
}
if(2*allbal<(i-allbal)) return false;
}
return (lastbal==0);
}
void fill_r(int bas,int son) {
int op=0;
int tot=son-bas+1;
for(int i=bas;i<=son;i++) op+=(s[i]=='(');
if(op>tot-op) {
int putG=op-(tot-op);
int putB=putG;
for(int i=son;i>=bas;i--) {
if(s[i]==')' && putG) {
--putG;
col[i]='G';
}
else if(s[i]==')') {
col[i]='R';
}
if(s[i]=='(' && putB) {
--putB;
col[i]='B';
}
else if(s[i]=='(') {
col[i]='R';
}
}
}
else {
int putG=(tot-op)-op;
int putB=putG;
for(int i=bas;i<=son;i++) {
if(s[i]=='(' && putG) {
--putG;
col[i]='G';
}
else if(s[i]=='(') {
col[i]='R';
}
if(s[i]==')' && putB) {
--putB;
col[i]='B';
}
else if(s[i]==')') {
col[i]='R';
}
}
}
}
void create(int now) {
int cur_op=0;
for(int i=now;i<=n;i++) {
if(s[i]=='(' && cur_op<0) {
fill_r(now,i-1);
create(i);
return ;
}
if(s[i]=='(') cur_op++;
else cur_op--;
}
fill_r(now,n);
}
void print() {
for(int i=1;i<=n;i++) printf("%c",col[i]);
puts("");
}
void find_ans() {
if(!check()) {
printf("impossible\n");
return ;
}
create(1);
print();
}
void solve1() {
while(t--) {
scanf("%s",s+1);
n=strlen(s+1);
find_ans();
}
}
void dp() {
cnt[1][0][0]=1;
for(int i=0;i<N;i++) {
for(int j=0;j<=i;j++) {
for(int k=0;k<=j;k++) {
if(j*2<i-j) cnt[1][j][k]=0;
cnt[0][j][k]=cnt[1][j][k];
if(k==0) res[i]=(res[i]+cnt[0][j][k])%MOD;
}
}
memset(cnt[1],0,sizeof(cnt[1]));
for(int j=0;j<=i;j++) {
for(int k=0;k<=j;k++) {
cnt[1][j+1][k+1]=(cnt[1][j+1][k+1]+cnt[0][j][k])%MOD;
cnt[1][j][max(0,k-2)]=(cnt[1][j][max(0,k-2)]+cnt[0][j][k])%MOD;
}
}
}
}
void solve2() {
dp();
while(t--) {
scanf("%d",&x);
printf("%d\n",res[x]);
}
}
int main() {
// freopen("input.txt","r",stdin);
scanf("%d %d",&p,&t);
if(p==1) solve1();
else solve2();
}컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
