Replay of BSMRSTU Home Quarantine Contest - 6

Schedule

The contest will start on 2020-06-01T14:00:00Z and will run for 3 hours.

Click here to learn more about this contest.

Link to editorial/solutions?

For the problem B- divisible by three, I have a flawless logic, but after long debugging I found out that cin>> takes only 4095 character. I tried to find a solution then gave up anon and the same problem strikes again. Can you please tell me how to avoid this limitation? I spent almost 160 min stuck on the problem and it is so frustrating to be stuck this way! a valid solution would be welcome also.
Here is my solution if it can help you:

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string t;
	cin>>t;
	int papo=(int)t.size();
	vector<int> pod;
	int j;
	pod.reserve(papo);
	for(auto s:t){
		j=s-'0';
		pod.emplace_back(j);
	}
	vector<ll> lop(3,0);
	int kayn=0;
	ll trm,tmp,smp;
	for(int i=0;i<papo;i++){
		if(pod[i]%3==0){
			kayn++;
			kayn+=lop[0];
			lop[0]++;
		}
		else if(pod[i]%3==1){
			kayn+=lop[1];
			trm=lop[0];
			tmp=lop[1];
			smp=lop[2];
			lop[0]=tmp;
			lop[1]=smp;
			lop[2]=trm;
			lop[2]++;
		}
		else if(pod[i]%3==2){
			kayn+=lop[2];
			trm=lop[0];
			tmp=lop[1];
			smp=lop[2];
			lop[0]=smp;
			lop[1]=tmp;
			lop[2]=trm;
			lop[1]++;
		}
	}
	cout<<kayn<<endl;
	return 0;
}

it works fine as long as the string is les than 4095 character!
Thank you

1 Like

Not sure aboutbthe actual solution to the problem, but I can see a similar discussion about the 4095 character limitation with cin on Stack Overflow: https://stackoverflow.com/a/22886300

It seems the limitation may stem from the editor’s copy/paste function.

In this case what does the judge use for standard input? if it uses files then there should be no problem about the input size. In this case there is a flaw in my program. I was debugging my logic with various cases and it was holding. I also tried to use a file for the input and it works just fine, or at least I have no ristriction about string length. I would be extremly frustrated if the problem is in my algorithm! Do you have an idea about what can go wrong with my code? Is there a way to watch other submissions?

cin cannot be a problem here, I myself used it, there is a logical flaw somewhere. Here is a testcase where your solution fails -
Input -
33312221333
Expected Output - 21
Generated Output - 32

1 Like

You are right, I debugged with this input and turns out my logic was false! it worked with small inputs and I was confident it was right! thank you for your hint!