SNCOUP - Editorial

Else you can paste your code as a answer so that other users can also take a chance to find error case

1 Like

Can any one tell me where my solution is failing…
https://www.codechef.com/viewsolution/13957070

whats wrong in This … ?

for _ in range(int(input())):
n = int(input())
s1 = str(input())
s2 = str(input())
s3 = str()
d = 0
for i in range(n):
    if s1[i] == '*' and s2[i] == '*':
        d+=1
        break
for j in range(n):
    if s1[j] == '*' or s2[j] == '*':
        s3+='*'

if d == 1 or len(s3) == 0:
    print(len(s3))
else:
    print(len(s3) - 1

thanxx man.

@urdarinda

Sorry I’m unable to find any case for which your code is not working.

I used a different approach, was getting a wrong answer but couldn’t figure a test case for which this will fail. Consider the number of β€˜'s in row 1 as stars1, and the number of stars in row2 as stars2. Also, for columns where both row 1 and row 2 have a '’, count them in a variable common. So the approach is that if(common>0), add a fence(the horizontal fence). And then the number of vertical fences that will be added will be= (stars1 + stars2- common -1) .
I cant figure out why will it fail.Can someone point out a test case. Here is the code:

https://www.codechef.com/viewsolution/13960878

thank you for trying! @sai_rathan
Can anyone provide a test case for which the code does not work?

1 Like

I Dare you if you can tell where it will fail.

@urdarinda

if(arr[0][i]=='*' && arr[1][i]=='.' && arr[0][i+1]=='.' && arr[1][i+1]=='*'){
                ans--;
                i++;
            }
            else if(arr[0][i]=='.' && arr[1][i]=='*' && arr[0][i+1]=='*' && arr[1][i+1]=='.'){
                ans--;
                i++;
            }

I think in the if condition your trying to access a[0][i+1] but when you are accessing last element it will try to access its next element which is not present. I think this is causing some trouble for larger value of β€˜n’ though I’m not sure.

Nice work @sai_rathan :slight_smile:

1 Like

The test cases already found where you were wrong so no point in dare XD.

On a side note- Request nicely and people will help :slight_smile:

2 Likes

Can any one help me out where I went wrong
https://www.codechef.com/viewsolution/13933535
I was really working from yesterday night and could not find where it is failing.So please and please help me out

#include<bits/stdc++.h>
#define S_ a[0][i]==’’ && a[1][i]==’.’
#define _S a[0][i]==’.’ && a[1][i]==’
’
#define SS a[0][i]==’’ && a[1][i]==’’
#define __ a[0][i]==’.’ && a[1][i]==’.’
#define SNAKE a[0][i+1]==’’||a[1][i+1]==’’
using namespace std;

int main(){

inputSection
//-----------------------------------------------
int firstIndex = 0;
int lastIndex=0;

for(int i=0;i<n;i++)
{

if(a[0][i]==’’ || a[1][i]==’’)

{
firstIndex = i;
break;
}
}

for(int i=n-1;i>=firstIndex;i–)
{

if(a[0][i]==’’ || a[1][i]==’’)
{
lastIndex = i;
break;
}
}
bool hz = false;
int vt =0;

if(firstIndex==lastIndex && a[0][firstIndex]==’’&&a[1][lastIndex]==’’)
{

hz=true;

}

else if(firstIndex==lastIndex)
{

hz = false;
vt=0;

}

for(int i = firstIndex;i<lastIndex;)
{

if(S_)
{

if(!SNAKE)
{i++;continue;}

i=i+1;
if(S_)

vt++;

else if(SS){hz=true;

vt++;}

else if(_S){

hz= true;

}

}

else if(_S){

if(!SNAKE)

{

i++;

continue;

}

i= i+1;

if(_S)

{

vt++;

}

else if(S_)
{

hz=true;
}

else if(SS){
hz= true;

vt++;

}

}

else if( SS){

if(!SNAKE)

{

i++;

continue;

}

i= i+1;

if(_S)

{

vt++;

hz=true;

}

else if(S_)
{

hz=true;

vt++;

}

else if(SS){
hz= true;
vt++;

}

else{
hz=true;
}

}

else // increment i
{i++;}

}

if(hz)

cout<<vt+1<<endl;

else

cout<<vt<<endl;

}

return 0;
}

**Can AnyOne help me in getting error in this code ** Here SOME Macros are used _–>Dot ans S–>Snake I m checking pair wise snake and next snake and then applying the opartion on vertical line and horizontal line i used a boolean for Hz line if it exists then add 1 to vertical lines…

https://www.codechef.com/viewsolution/13933535
This is the link to mmy code.So please help me out where I went wrong

If anyone want’s to check out a correct


[1]

It's quite simple 


  [1]: https://www.codechef.com/viewsolution/13932694

Anyone who can tell me a test case ? Here is my code. Getting WA for no reason.

 #include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,t;
	char a[200010];
	char b[200010];
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		scanf(" %s",a);
		scanf(" %s",b);
		int cnt=0;
        int upper=0;
        int lower=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]=='*')
                upper++;
            if(b[i]=='*')
                lower++;
            if(upper>=1 && lower>=1)
            {
                cnt=1;
                break;
            }
        }
        upper=lower=0;
		for(int i=0;i<n;i++)
		{
			if(a[i]=='*' && b[i]=='*')
                cnt++;
            else if(a[i]=='*')
            {
                upper++;
                cnt++;
            }
            else if(b[i]=='*')
            {
                lower++;
                cnt++;
            }
            if(upper==1 && lower ==1)
            {
                cnt--;
                lower=upper=0;
            }
            if(lower>1 || upper>1)
            {
                if(a[i]=='*' && b[i]=='.')
                {
                        upper=1;
                        lower=0;
                }
                else if(b[i]=='*' && a[i]=='.')
                {
                    lower=1;
                    upper=0;
                }
                else
                    upper=lower=0;
            }
            //printf("at %d count= %d\n",i,cnt);
		}
		if(cnt)
            cnt--;
		printf("%d\n",cnt);
	}
	return 0;
}

doing i-- in the last loop won’t cause the loop to run infinitely? In c++ code given here?

//ANYHELP why this code is not accepted?
#include
#include
#include
#include
#include

using namespace std;
 
    int main(){
 
int t;
cin>>t;
for(int r=0;r<t;r++){
           int q;
          cin>>q;
      char s[2][q];
    char d;
for(int i=0;i<2;i++){
for(int j=0;j<q;j++)
 cin>>s[i][j];
 }  
 int c=0;
    for(int i=0;i<2;i++){
for(int j=0;j<q;j++)
 if(s[i][j]=='*')c++;
 }    
 
    int count=0;
  int s1=0;
 int s2=0;
 d='a';
for(int k=0;k<q;k++){
if(s[0][k]=='*' || s[1][k]=='*') count++;
  if(s[0][k]=='*') s2=1;
if(s[1][k]=='*') s1=1;
if(s[0][k]=='*' && s[1][k]=='*') d='c';
}
int hor=s1+s2;
 
if(d=='c'){
if(count-1 == 1 && hor==2 && c>2){cout<<2<<endl;  }
  if(count-1 == 0 && hor==2 && c==2){cout<<1<<endl;  }
  if(count-1 == 1 && hor==2 && c==2){cout<<1<<endl;  }
if(count-1 > 1 && hor==2 ){cout<<count+hor-2<<endl;  }
if(count-1 >= 1 && hor!=2 ){cout<<count-1<<endl;  }
if(count-1 ==0 && hor!=2 ){cout<<0<<endl;  }
if(count-1 ==0 && hor!=2 && c==2){cout<<1<<endl;  }
 
}
 
else if(d!=c){
  if(count>=1)cout<<count-1<<endl; 
  else cout<<0<<endl;}
 
 
}
return 0;
                                              
}

  1. Blockquote

link text
anyhelp on why this code not accepted will be highly appreciated!!

Can anyone please provide a test case where my code fails?

Solution link : https://ideone.com/AVh0zv
Thanks:)