QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#591584#5534. Matchifffer_21370 16ms129376kbC++141.1kb2024-09-26 16:37:272024-09-26 16:37:27

Judging History

你现在查看的是最新测评结果

  • [2024-09-26 16:37:27]
  • 评测
  • 测评结果:0
  • 用时:16ms
  • 内存:129376kb
  • [2024-09-26 16:37:27]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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%