< Back to forum

my code is running correct but i got only partial scores....in other score constraint it is giving SIGSEGV ERROR in codechef....link to questn https://www.codechef.com/problems/XENRANK

#include<bits/stdc++.h>
using namespace std;
 
int main()
{
long long int t,c,i;
cin>>t;
c=0;
long long int a[100000];
for(i=1;i<100000;i++)
{
c=c+i;
a[i]=c;
}
 
while(t--)
{
long int x,y,z,i,s;
cin>>x>>y;
z=x+y;
s=a[z];
s++;
s=s+x;
cout<<s<<endl;
}
return 0;
}
 

 

Asked by: Manish_Kumar_Savita on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.


Enter your answer details below:


Enter your comment details below:




1 Answer(s)

avatar

See the constraints

1 ≤ U, V ≤ pow(10,9)

the maximum size of your array a is 100000. So in your code when (x+y)>=100000,segmentation fault(SIGSEGV) occurs.

z=x+y;
s=a[z];

I have no idea what made to choose this limit of 100000!

READ PROBLEM CONSTRAINTS CAREFULLY.!...When you are writing code try to understand what each line of your code does ...take your time. Don't just do stuff randomly hoping it would work out.

Shubham_Kumar_Gupta last updated on April 7, 2019, 6:34 p.m. 0    Reply    Upvote   

Instruction to write good question
  1. 1. Write a title that summarizes the specific problem
  2. 2. Pretend you're talking to a busy colleague
  3. 3. Spelling, grammar and punctuation are important!

Bad: C# Math Confusion
Good: Why does using float instead of int give me different results when all of my inputs are integers?
Bad: [php] session doubt
Good: How can I redirect users to different pages based on session data in PHP?
Bad: android if else problems
Good: Why does str == "value" evaluate to false when str is set to "value"?

Refer to Stack Overflow guide on asking a good question.