样例都过但0pts全wa求调或hack(码风简洁舒适)
查看原帖
样例都过但0pts全wa求调或hack(码风简洁舒适)
360611
Love_Stream楼主2023/8/28 18:29
#include<bits/stdc++.h>
#define int long long
using namespace std;
string s;
int n,ans,tag;
stack<char> sta;

int opt[1000005];

signed main(){
	cin >> s;
	n = s.size();
	s = ' ' + s;
	for(int i = 1;i <= n;i++){
		if(!sta.size())
			sta.push(s[i]);
		else if(s[i] == ')' && sta.top() == '(' || s[i] == ']' && sta.top() == '['){
			opt[i] = opt[i - 1] + 2;
			sta.pop();
		}
		else {
			sta.push(s[i]);
		}
		if(opt[i] > ans)
			ans = opt[i],tag = i;
	}
	
	for(int i = tag - ans + 1;i <= tag;i++){
		cout << s[i];
	}
	cout << endl;
	return 0;
}
2023/8/28 18:29
加载中...