Submission #56827

# Submission time Handle Problem Language Result Execution time Memory
56827 2018-07-12T16:52:05 Z mraron Match (CEOI16_match) C++14
37 / 100
93 ms 9260 KB
/*
ID: noszaly1
TASK: {TASK}
LANG: C++11               
*/

//Noszály Áron 10o Debreceni Fazekas Mihály Gimnázium

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

ll mod=1e9+7;
ll p=13;

string t;

ll st[100001], en[100001];
map<int, vector<int>> lst;
string ans;

void solve(int L, int R) {
	if(L>R) return ;
	//cerr<<L<<" "<<lst[en[L]].back()<<" "<<R<<"\n";
	while(lst[en[L]].back()>R) lst[en[L]].pop_back();
	//assert(!lst[en[L]].empty() && lst[en[L]].back()<=R);
	
	int par=lst[en[L]].back();
	
	ans[L]='(';
	ans[par]=')';
	
	lst[en[L]].pop_back();
	
	solve(par+1, R);
	solve(L+1, par-1);
}

int main() {
	IO;
	cin>>t;
	
	stack<pair<char,ll>> s;
	
	int ind=0;
	for(auto i:t) {
		if(s.empty()) {
			st[ind]=-1;
		}else {
			st[ind]=s.top().yy;
		}
		
		if(!s.empty() && s.top().xx==i) {
			s.pop();
		}else {
			if(s.empty()) {
				s.push({i, i});
			}else {
				s.push({i, (i+p*s.top().yy)%mod});
			}
		}
		
		if(s.empty()) {
			en[ind]=-1;
		}else {
			en[ind]=s.top().yy;
		}
		
		ind++;
	}
	
	if(!s.empty()) {
		cerr<<"-1\n";
		return 0;
	}

	
	for(int i=0;i<sz(t);++i) {
		//cerr<<st[i]<<" "<<en[i]<<"\n";
		lst[st[i]].pb(i);
	}
	
	ans=string(sz(t), '*');
	
	solve(0, sz(t)-1);
	
	cout<<ans<<"\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 3 ms 464 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 2 ms 440 KB Output is correct
4 Correct 3 ms 464 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 5 ms 1152 KB Output is correct
10 Correct 6 ms 1184 KB Output is correct
11 Correct 6 ms 1312 KB Output is correct
12 Correct 55 ms 6396 KB Output is correct
13 Correct 58 ms 6932 KB Output is correct
14 Correct 64 ms 7952 KB Output is correct
15 Correct 16 ms 7952 KB Output is correct
16 Correct 19 ms 7952 KB Output is correct
17 Correct 56 ms 7952 KB Output is correct
18 Correct 20 ms 7952 KB Output is correct
19 Incorrect 93 ms 9260 KB Output isn't correct
20 Halted 0 ms 0 KB -