이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
set <int> h[30] ;
priority_queue <int> small;
set <int> :: iterator it , it2;
int s[100010];
char sol[100010];
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int n , i , ok , ed;
char c;
c=fgetc(fin);
n = 0;
while ( 'a' <= c && c <= 'z' ){
s[++n] = c-'a';
h[c-'a'].insert(n); /// pozitii
c=fgetc(fin);
}
ok = 1;
small.push(-n-1);
for ( i = 1 ; i <= n ; i++ ){
if (sol[i] == 0){
/// nu ai pus inca
sol[i] = '(';
while (!small.empty() && -small.top() < i)
small.pop();
/// small.top() = cea mai mica poz a unei paranteze inchise
it = h[s[i]].lower_bound(-small.top());
it--;
ed = *it;
if (ed <= i){
ok = -1;
break;
}
else {
/// sfarsitul de acum trebuie sa fie mai mic decat sfarsiturile
/// mai mari decat i
h[s[i]].erase(it);
sol[ed] = ')';
small.push(-ed);
}
}
}
if (ok == -1){
fprintf (fout,"%d",ok);
}
else {
for (i=1;i<=n;i++)
fputc(sol[i],fout);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |