QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#591584 | #5534. Match | ifffer_2137 | 0 | 16ms | 129376kb | C++14 | 1.1kb | 2024-09-26 16:37:27 | 2024-09-26 16:37:27 |
Judging History
answer
//From: ifffer_2137
#include <bits/stdc++.h>
using namespace std;
#define inf 0x7fffffff
#define eb emplace_back
#define pii pair<int,int>
#define mkpr make_pair
#define fir first
#define sec second
inline int read(){
char ch=getchar();int x=0,w=1;
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-48,ch=getchar();return w==1?x:-x;
}
const int maxn=2e3+5;
int n;
string s;
string dp[maxn][maxn];
signed main(){
#ifndef ONLINE_JUDGE
freopen("data.in","r",stdin);
freopen("test.out","w",stdout);
#endif
cin.tie(0),cout.tie(0);
cin>>s;n=s.size();s=' '+s;
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dp[i][j]="0";
for(int i=2;i<=n;i++){
for(int l=1;l+i-1<=n;l++){
int r=i+l-1;
if(s[l]==s[r]){
if(l+1<r&&dp[l+1][r-1]!="0") dp[l][r]=min(dp[l][r],'('+dp[l+1][r-1]+')');
else dp[l][r]=min(dp[l][r],(string){"()"});
}
for(int j=l;j<r;j++){
if(dp[l][j]=="0"||dp[j+1][r]=="0") continue;
dp[l][r]=min(dp[l][r],dp[l][j]+dp[j+1][r]);
}
}
}
if(dp[1][n]=="0") puts("-1");
else cout<<dp[1][n]<<"\n";
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 15ms
memory: 129200kb
input:
abbaaa
output:
(()())
result:
ok single line: '(()())'
Test #2:
score: 10
Accepted
time: 12ms
memory: 129208kb
input:
cbbbbccbbccbbbbbbc
output:
(((((((()))())))))
result:
ok single line: '(((((((()))())))))'
Test #3:
score: 0
Wrong Answer
time: 16ms
memory: 129376kb
input:
ddbcbdacccbddaba
output:
(((())))()
result:
wrong answer 1st lines differ - expected: '-1', found: '(((())))()'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%