답안 #61943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61943 2018-07-27T06:00:37 Z khsoo01 parentrises (BOI18_parentrises) C++11
100 / 100
131 ms 55312 KB
#include<bits/stdc++.h>
using namespace std;

const int N = 2000005;

int n;
char a[N], b[N];

void solve1 () {
	scanf("%s",a+1);
	n = strlen(a+1);
	queue<int> X, Y, Q;
	int A = 0, B = 0, C = 0, D = 0;
	for(int i=1;i<=n;i++) {
		if(a[i] == '(') {
			if(D < C) {
				D++;
				B++;
				b[i] = 'R';
				Y.push(i);
			}
			else {
				C++;
				A++;
				b[i] = 'B';
				X.push(i);
			}
		}
		else {
			A--;
			B--;
			b[i] = 'G';
			Q.push(i);
		}
		while(A < 0 && !Y.empty()) {
			int T = Y.front();
			Y.pop();
			b[T] = 'G';
			A++;
		}
		while(B < 0 && !X.empty()) {
			int T = X.front();
			X.pop();
			b[T] = 'G';
			B++;
		}
		while(A < 0 && !Q.empty()) {
			int T = Q.front();
			Q.pop();
			b[T] = 'R';
			A++;
		}
		while(B < 0 && !Q.empty()) {
			int T = Q.front();
			Q.pop();
			b[T] = 'B';
			B++;
		}
		if(A < 0 || B < 0) {
			puts("impossible");
			return;
		}
	}
	if(A > 0 || B > 0) {
		puts("impossible");
		return;
	}
	b[n+1] = 0;
	printf("%s\n",b+1);
}

const int M = 301, mod = 1e9+7;

int dt[M][M][M];

void calc () {
	dt[0][0][0] = 1;
	for(int i=1;i<M;i++) for(int j=0;j<i;j++) for(int k=0;k<i;k++) {
		if(k >= 2) {
			dt[i][j+1][k-2] = (dt[i][j+1][k-2] + dt[i-1][j][k]) % mod;
		}
		else if(j+k >= 1) {
			dt[i][j+k-1][0] = (dt[i][j+k-1][0] + dt[i-1][j][k]) % mod;
		}
		dt[i][j+1][k+1] = (dt[i][j+1][k+1] + dt[i-1][j][k]) % mod;
	}
}

void solve2() {
	int T, R = 0;
	scanf("%d",&T);
	for(int i=0;i<M;i++) {
		R = (R + dt[T][i][0]) % mod;
	}
	printf("%d\n",R);
}

int main()
{
	int typ, tc;
	scanf("%d%d",&typ,&tc);
	if(typ == 2) calc();
	while(tc--) {
		if(typ == 1) solve1();
		else solve2();
	}
}

Compilation message

parentrises.cpp: In function 'void solve1()':
parentrises.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",a+1);
  ~~~~~^~~~~~~~~~
parentrises.cpp: In function 'void solve2()':
parentrises.cpp:91:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&T);
  ~~~~~^~~~~~~~~
parentrises.cpp: In function 'int main()':
parentrises.cpp:101:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&typ,&tc);
  ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 664 KB Output is correct
2 Correct 3 ms 664 KB Output is correct
3 Correct 3 ms 664 KB Output is correct
4 Correct 2 ms 664 KB Output is correct
5 Correct 3 ms 720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 664 KB Output is correct
2 Correct 3 ms 664 KB Output is correct
3 Correct 3 ms 664 KB Output is correct
4 Correct 2 ms 664 KB Output is correct
5 Correct 3 ms 720 KB Output is correct
6 Correct 2 ms 720 KB Output is correct
7 Correct 4 ms 720 KB Output is correct
8 Correct 3 ms 720 KB Output is correct
9 Correct 2 ms 720 KB Output is correct
10 Correct 3 ms 720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 664 KB Output is correct
2 Correct 3 ms 664 KB Output is correct
3 Correct 3 ms 664 KB Output is correct
4 Correct 2 ms 664 KB Output is correct
5 Correct 3 ms 720 KB Output is correct
6 Correct 2 ms 720 KB Output is correct
7 Correct 4 ms 720 KB Output is correct
8 Correct 3 ms 720 KB Output is correct
9 Correct 2 ms 720 KB Output is correct
10 Correct 3 ms 720 KB Output is correct
11 Correct 3 ms 720 KB Output is correct
12 Correct 2 ms 720 KB Output is correct
13 Correct 3 ms 720 KB Output is correct
14 Correct 3 ms 720 KB Output is correct
15 Correct 3 ms 720 KB Output is correct
16 Correct 13 ms 720 KB Output is correct
17 Correct 5 ms 1024 KB Output is correct
18 Correct 4 ms 1024 KB Output is correct
19 Correct 5 ms 1024 KB Output is correct
20 Correct 5 ms 1040 KB Output is correct
21 Correct 71 ms 1296 KB Output is correct
22 Correct 24 ms 5648 KB Output is correct
23 Correct 14 ms 5648 KB Output is correct
24 Correct 20 ms 5648 KB Output is correct
25 Correct 26 ms 5648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 55312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 55312 KB Output is correct
2 Correct 112 ms 55312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 55312 KB Output is correct
2 Correct 112 ms 55312 KB Output is correct
3 Correct 131 ms 55312 KB Output is correct