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 15?
Author: Criminal_Leopard
ID: 062859
Problem: 546
Contest: 0
Date: 2014-10-21 17:04:25

Here is my code in c++;

#include<iostream>
using namespace std;

typedef pair<int,int>pii;

const int maxn=210;
int d[3],e[3],n,a,b,ans[maxn],counter=0;
string p;

pii f(int x)
{
if(x==0)
return pii(1,2);
if(x==1)
return pii(0,2);
return pii(0,1);
}

int main()
{
cin>>n>>a>>b>>p;
e[0]=a;
e[1]=b;
e[2]=n-a-b;
int s=p.size();
for(int i=0;i<p.size();i++)
{
ans[i]=p[i]-48;
d[ans[i]]++;
}
for(int i=0;i<s;i++)
{
pii k=f(ans[i]);
if(d[ans[i]]>e[ans[i]])
{
if(d[k.first]<e[k.first])
{
d[k.first]++;
d[ans[i]]--;
ans[i]=k.first;
counter++;
}
else if(d[k.second]<e[k.second])
{
d[k.second]++;
d[ans[i]]--;
ans[i]=k.second;
counter++;
}
else
{
cout<<"-1n";
return 0;
}
}
}
cout<<counter<<endl;
for(int i=0;i<s;i++)
cout<<ans[i];
cout<<endl;
}


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-09-21 11:03:09Online Contester Team © 2002 - 2016. All rights reserved.