Saratov State University :: Online Contester


::Go
- home
- news
- register
- update personal info
- problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- links
- projects

::Poll
Are you registered on Codeforces?
Yes
No
What is it???

[results]

::webboard

why WA on test 5?? give me some test plz
Author: Taraneh
ID: 044030
Problem: -
Contest: -
Date: 2011-12-01 19:53:34

#include<iostream>
#include<string>
using namespace std;

const int maxn=1000+20;
int a[maxn], b[maxn];
string s;

int main(){
int x;
cin>>s;
for (int i=0; i<s.size(); i++){
if (s[i]=='(')
b[i]=1;
if (s[i]==')')
b[i]=-1;
}
for (int i=0; i<s.size(); i++){
if (i==0)
a[i]=b[i];
else
a[i]=a[i-1]+b[i];
}
int flag=0;
for (int i=0; i<s.size(); i++)
if (a[i]==2)
flag=1;
if (flag==0){
cout<<"No solution"<<endl;
return 0;
}
for (int i=s.size()-1; i>=0; i--)
if (a[i]==2 && b[i]==1 && (s.size()-i-1)%2==0){
b[i]=-1;
x=i;
break;
}
int cur=s.size()-x-1;
int ans=0;
for (int i=x+1; i<s.size(); i++){
ans++;
if (ans<=cur/2)
b[i]=1;
else if (ans>cur/2)
b[i]=-1;
}
for (int i=0; i<s.size(); i++){
if (b[i]==1)
cout<<'(';
else
cout<<')';
}
return 0;
}


see sub-tree reply to that message


::Login
Forgot password?

::News
22.10.12 - The problems from the Southern Subregional Programming Contest 2012 added to the problemset archive (542 - 553).
22.10.12 - After the start of the contest the statements in PDF will be available by the link.
23.10.11 - The problems from the Southern Subregional Programming Contest 2011 added to the problemset archive (530 - 541).

::Counter

Server time: 2017-11-22 04:44:24Online Contester Team © 2002 - 2016. All rights reserved.