제출 #42432

#제출 시각아이디문제언어결과실행 시간메모리
42432nonocut괄호 문자열 (CEOI16_match)C++14
37 / 100
19 ms820 KiB
#include<bits/stdc++.h>
using namespace std;
#define pci pair<char,int>
#define X first
#define Y second
const int maxn = 2e3 + 5;
int n;
char s[maxn];
int fix[maxn];
pci a[maxn];
bool check() {
	int r = 0;
	for(int i=0;i<n;i++) {
		a[++r] = {s[i],fix[i]};
		while(r>=2 && a[r].X==a[r-1].X) {
			if(a[r].Y==0 || (a[r-1].Y==-1 && a[r].Y==1)) r-=2;
			else break;
		}
	}
	return (r==0);
}
int main() {
	scanf(" %s",s);
	n = strlen(s);
	for(int i=0;i<n;i++) {
		fix[i] = -1;
		if(!check()) fix[i] = 1;
	}
	if(check()) {
		for(int i=0;i<n;i++) printf("%c", (fix[i]==-1 ? '(' : ')'));
	}
	else printf("-1");
}

컴파일 시 표준 에러 (stderr) 메시지

match.cpp: In function 'int main()':
match.cpp:23:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf(" %s",s);
                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...