이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stack>
#include <ctype.h>
#define p(x,y) pair<x, y>
#define pii pair<int, int>
#define v(x) vector<x>
#define q(x) queue<x>
#define pq(x) priority_queue<x>
#define uppq(x, comp) priority_queue<x, vector<x>, comp>
#define st(x) set<x>
#define m(x, y) map<x, y>
#define fi(s,e) for(int i=s;i<e;i++)
#define fj(s,e) for(int j=s;j<e;j++)
#define fk(s,e) for(int k=s;k<e;k++)
typedef long long int ll;
typedef unsigned long long int ull;
typedef __int128 ulll;
using namespace std;
int dp[100010][30];
char s[100010];
char ans[100010];
int chk;
void find(int l, int r){
if(l>r) return;
if(dp[r][s[l]-'a'] <= l){
chk=-1;
return;
}
int mid = dp[r][s[l]-'a'];
ans[l]='(';
ans[mid]=')';
find(l+1, mid-1);
find(mid+1, r);
return;
}
int main(void){
scanf("%s",s);
int l = strlen(s);
fi(0,l){
fj(0,'z'-'a'+1){
dp[i][j]=-1;
if(s[i]-'a' == j) dp[i][j]=i;
if(i && dp[i-1][s[i]-'a'] > 0) dp[i][j] = max(dp[i][j], dp[dp[i-1][s[i]-'a']-1][j]);
}
}
find(0,l-1);
if(chk==-1){printf("-1\n");return 0;}
fi(0,l) printf("%c",ans[i]);
printf("\n");
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
match.cpp: In function 'int main()':
match.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | scanf("%s",s);
| ~~~~~^~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |