| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1117714 | vjudge1 | 괄호 문자열 (CEOI16_match) | C++17 | 71 ms | 336 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int sz=2e5+5;
const int MOD=1e9+7;
const int INF=1e18;
bool check(string cur,string s,int b,int e)
{
map<int,bool> used;
for(int i=b;i<e;i++)
{
bool checker=false;
if(used[i])
continue;
used[i]=true;
for(int j=e-1;j>=b;j--)
{
if(s[j]==s[i] && cur[i]=='(' && cur[j]==')' && !used[j])
{
used[j]=true;
checker=check(cur,s,i+1,j);
break;
}
}
if(!checker)
return false;
}
return true;
}
void solve()
{
string s,res="",checker="";
cin>>s;
for(int i=0;i< s.size();i++)
{
res+=')';
checker+=')';
}
int n=s.size();
for(int mask=1;mask<(1<<n);mask++)
{
string cur="";
for(int j=0;j<n;j++)
{
if(mask & (1<<j))
cur+='(';
else
cur+=')';
}
if(check(cur,s,0,s.size()))
res=min(res,cur);
}
if(res==checker)
cout<<-1;
else
cout<<res;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
//cin>>t;
while(t--)
{
solve();
}
}컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
