Consider the test input:
1
1 9 3
1
Consider the test input:
1
1 9 3
1
Thank you very much . I got the mistake and now it is running correctly .
CodeChef: Practical coding for everyone : link to my solution.
What changes should I make to my code for it to work?
Thanks.
Can someone please point out the problem with my code. Here is the link to my code:
https://www.codechef.com/viewsolution/49796754
I know it’s failing but I am unable to get where I have made the mistake.
Hello!
3
4 7 8
12 52 56 8
2 10 2
21 75
2 5 8
10 51
0
18
9
*** stack smashing detected ***: terminated
Aborted (core dumped)
Process returned 134 (0x86) execution time : 1.402 s
Press ENTER to continue.
I am having above error in this question code goes here:-
#include <bits/stdc++.h>
using namespace std;
/*
[1,2,3,4,5,6,7]
1 2 3 4 5 6 7 */
/*
void color(int arr[],int start,int endd){
for(int i = start-1;i<endd;++i)
{
arr[i]=1; // 1 means covered and not safe
}
}*/
int main()
{
long t;
cin>>t;
for(int k = 0;k<t;++k)
{ int A[100] = {0};
int M,x,y;
cin>>M>>x>>y;
int cpos=0;
for(int i=0;i<M;++i)
{
cin>>cpos;
int st = cpos-(x*y);
if(st<1){
st =1;
}
int en = cpos+(x*y);
//color(A,st,en);
for(int i = st-1;i<en;++i)
{
A[i]=1; // 1 means covered and not safe
}
}
cout<<count(A,A+100,0)<<"\n";
}
}
Explanation:- for possible ranges of cops made the corresponding locations = 1 and counted the positions where safe houses are present.
Solution Logic : 100% correct
Problem: STACK SMASHING ERROR ie runtime error SIGSEGV