제출 #862696

#제출 시각아이디문제언어결과실행 시간메모리
862696MilosMilutinovic괄호 문자열 (CEOI16_match)C++14
10 / 100
1 ms696 KiB
#include<bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

char s[100005];
int lst[100005][26];

void solve(int l,int r){
	if(l>r) return;
	int c=s[l]-'a',p=lst[r][c];
	if(p<=l){printf("-1\n");exit(0);}
	s[l]='('; s[p]=')';
	solve(l+1,p-1);
	solve(p+1,r);
}

int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	for(int i=1;i<=n;i++){
		for(int j=0;j<26;j++) lst[i][j]=lst[i-1][j];
		lst[i][s[i]-'a']=i;
	}
	solve(1,n);
	printf("%s\n",s+1);
	return 0;
}

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

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