제출 #63036

#제출 시각아이디문제언어결과실행 시간메모리
63036hamzqq9parentrises (BOI18_parentrises)C++14
100 / 100
86 ms4652 KiB
#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 print() {
 
	for(int i=1;i<=n;i++) printf("%c",col[i]);
 
	puts("");
 
}

void dec() {

	stack<int> pos;
	int tot=0;

	for(int i=n;i>=1;i--) {

		if(s[i]==')') {

			tot++;

		}
		else {

			if(tot) {

				tot--;

				pos.push(i);

			}
			else {

				int a=pos.top();

				pos.pop();

				col[a]='B';
				col[i]='R';

			}

		}


	}

}
 
void inc() {

	stack<int> pos;
	int tot=0;

	for(int i=1;i<=n;i++) {

		if(s[i]=='(') {

			tot++;

			col[i]='G';

		}
		else {

			if(!tot) {

				int a=pos.top();

				pos.pop();

				col[a]='R';
				col[i]='B';

			}
			else {

				tot--;

				col[i]='G';

				pos.push(i);

			}

		}

	}

}

void find_ans() {
 
	if(!check()) {
 
		printf("impossible\n");
 
		return ;
 
	}
 
	inc();

	dec();
 
	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) 메시지

parentrises.cpp: In function 'void solve1()':
parentrises.cpp:164:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",s+1);
   ~~~~~^~~~~~~~~~
parentrises.cpp: In function 'void solve2()':
parentrises.cpp:217:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&x);
   ~~~~~^~~~~~~~~
parentrises.cpp: In function 'int main()':
parentrises.cpp:229:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&p,&t);
  ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...