Please attach the Practice link to problem
Can somebody explain case 1 more clearly?
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,a_i,b_i,a_t,t,co,h1,h2,l,fence,n,f,s,fence2;
cin>>t;
for(a_t=1;a_t<=t;a_t++)
{
string str1,str2;
cin>>n>>str1>>str2;
l=n;
h1=0;h2=0;fence=0;
for(a_i=0;a_i<l;a_i++)
{
if(str1.at(a_i)==’’)
h1++;
if(str2.at(a_i)==’’)
h2++;
}
if((h1+h2)<=1)
{
cout<<0<<endl;
continue;
}
else if((h1+h2)==2)
{
cout<<1<<endl;
continue;
}
//
else if(h1==0)
{
cout<<(h2-1)<<endl;
continue;
}
else if(h2==0)
{
cout<<(h1-1)<<endl;
continue;
}
//
fence=1;f=0;s=0;
/*for(a_i=0;a_i<l;a_i++)
{
if(str1.at(a_i)=='*'&&str2.at(a_i)=='*')
{
fence2=1;
break;
}
}*/
for(a_i=0;a_i<l;a_i++)
{
if(str1.at(a_i)=='*')
{
f++;
//h1--;
}
if(str2.at(a_i)=='*')
{
s++;
//h2--;
}
if(f==2&&s!=2)
{
fence++;
f=1;
//s=s;
}
if(s==2&&f!=2)
{
fence++;
s=1;
//f=0;
}
if(s==2&&f==2)
{
fence++;
s=1;
f=1;
}
}
cout<<fence<<endl;
}
}
in which case it’s not correct? what’s wrong with it??
in which case it is wrong??
can anyone explain??
#include<iostream>
using namespace std;
//int iequ(int m,int n,int a[m][n]);
int main(){
int t;
scanf("%d", &t);
for(int i=0;i<t;i++){
int n;
scanf("%d",&n);
char a[2][n];
int b1[n],b2[n];
int ind1=-1,ind2=-1;
for(int j=0;j<2;j++){
for(int k=0;k<n;k++){
//scanf("%c",&a[j][k]);
cin>>a[j][k];
}
}
int hflag=0,count=0;
for(int p=0;p<n;p++){
if(a[0][p]=='*'){
// if(a[1][p]=='*' || a[1][p+1]=='*'){
for(int u=p;u<n;u++){
if(a[1][u]=='*'){
hflag=1;
count++;
u=n;
p=n;
}
}
}
}
int rw;
if(hflag==1){
//cout<<"hi"<<endl;
for(int x=0;x<n;x++){
for(int y=0;y<2;y++){
if(a[y][x]=='*'){
for(int z=x+1;z<n;z++){
if(a[y][z]=='*'){
if(y==0){
rw=1;
}
else{
rw=0;
}
int fff=0;
for(int l=x;l<=z;l++){
if(a[rw][l]=='*'){
fff=1;
int ff=0;
for(int o=l+1;o<=z;o++){
if(a[rw][o]=='*'){
count++;
ff=1;
y=rw-1;
x=o;
o=z+1;
}
}
if(ff==0){
count++;
x=z;
y=y-1;
}
l=z+1;
}
}
if(fff==0){
count++;
y=y-1;
x=z;
}
z=n+1;
}
}
}
}
}
}
else{
for(int x=0;x<n;x++){
for(int y=0;y<2;y++){
if(a[y][x]=='*'){
for(int z=x+1;z<n;z++){
for(int i1=0;i1<2;i1++){
if(a[i1][z]=='*'){
count++;
y=i1-1;
x=z;
i1=2;
z=n;
}
}
}
}
}
}
}
cout<<count<<endl;
}
}
This problem seemed really easy to me, as I deducted pretty much exactly what the editorial says in the first hour of the contest. But I got about 12 WA’s. Why? I have no clue what test case could possibly fail.
What is wrong with my this code, it is working fine for all tests which i could think.
Please can someone tell where it is failing ???
https://www.codechef.com/viewsolution/13954302
what is wrong in my code
#include<stdio.h>
int main()
{
int T,i;
scanf("%d",&T);
for(i=0;i<T;i++)
{
int n,c=0,d=0,u=0,p=0,h=0,s=0,j,e=-1;
scanf("%d",&n);
char A[2][n+1];
scanf("%s",A[0]);
scanf("%s",A[1]);
for(j=0;j<n;j++)
{
if(s==0)
{
if((A[0][j]=='*')&&(A[1][j]=='*'))
{
c++;
h=1;
p=1;
s=1;
u=1;
d=1;
e=c;
}
else if(A[0][j]=='*')
{
u=1;
s=1;
p=1;
}
else if(A[1][j]=='*')
{
d=1;
s=1;
p=1;
}
}
else
{
if((A[0][j-1]=='*')&&(p==1)&&(u==0)&&(e<c))
{
u=1;s=1;e=c;
}
if((A[1][j-1]=='*')&&(p==1)&&(d==0)&&(e<c))
{
d=1;s=1;e=c;
}
if((A[0][j]=='*')&&(A[1][j]=='*'))
{
if(h==0)
{
c++;
h=1;
if((u==1)||(d==1))
{
c++;
u=0;
d=0;
}
}
else
{
if((u==1)||(d==1))
{
c++;
u=0;
d=0;
}
}
}
else if(A[0][j]=='*')
{
if(h==0)
{
if(d==1)
{
h=1;
c++;
}
else if(u==1)
{
c++;
u=0;
d=0;
}
}
else
{
if(u==1)
{
c++;
u=0;
d=0;
}
}
}
else if(A[1][j]=='*')
{
if(h==0)
{
if(u==1)
{
h=1;
c++;
}
else if(d==1)
{
c++;
u=0;
d=0;
}
}
else
{
if(u==1)
{
c++;
u=0;
d=0;
}
}
}
}
}
if(s==1)
printf("%d\n",c);
else
printf("%d\n",0);
}
return 0;
}
The main logic was to find that for the test case(s) with
1010 0101 10|10 _____ 01|01
The answer would be 2 (one horizontal and one vertical). Basically, you need to find every alternating snake occupied houses sub-array. Count the number of alternating snake occupied houses (say, x) and the number of walls in this sub-array would be (x-1)/2. (in this case, (4-1)/2 = 1, plus the horizontal one)
You don’t need to put a vertical wall between 2 alternating snake occupied houses if the horizontal wall already separates them.
Yes, I tested for that exception at the beginning.
@devilhector My code for only one line containing 's was to split on "" with a -1 modifier and subtract 2 from the resulting length. Through numerous copy and pasting, the -2’s became -1’s from an earlier submission. This is very frustrating.
I have a much simpler solution than this official solution.
i have done the question in exactly the same manner still i got wrong answer . I dont have enough karma to upload my solution . Is thera any way that i can get to know which case i am missing
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
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:
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