Yeah, I guess it should be marked which direction is which. From the problem statement it is not clear. In the problem the x direction goes from top to bottom and the y-direction from left to right which is not what one might expect especially if one is used to the standard Euclidean coordinate system.
what is wrong in my solution?
I have first of all calculated each cell value by following process:
row head as first cell of row 1.
as nth term in first row can be calculated as
Tn=1+T1+T2+T3+ …+ Tn-1
=>Tn=1+1+2+3+…+(N-1)
=>Tn=1+ x*(x-1)/2 //x=n
and similarly then nth term in that colomn using row_head
as
T1=row_head
T2=T1+x+1=row_head+x+1
T3=T2+x+1+1=row_head+(x+1)+1
…
…
…
Ty=row_head+(y-1)(x+1)+(y-2)(y-1)/2 //this is our cell value;
and then in main i use cellvalue to get path reach x2,y2.
help…
my code------------------------------------------------
Yeah a[1000][1000] won’t work because if you think logically like if you make the matrix of a[3][3]
Blockquote
1 2 4
3 5
6
indexing for them is like (1 - based )
Blockquote
11 12 13
21 22 23
31 32 33
if i ask you accordingly now what’s value a a[3][3] ? i.e. is nothing you can see in the first matrix
so for a[1000][1000] you have to make it a[2000][2000] cz then a[1000][1000] = 0
If we consider the size of the matrix to be (3 * 3) it will of the form:
1 2 4
3 5 0
6 0 0
and trying to build a (3 * 3) matrix completely would result in something of the form:
1 2 4
3 5 7
6 8 9
Which has 9 at index (3,3) while it should have been 13,which will obviously result into WA.
Guys, I did my code but was getting WA again and again and cause i took the array size as [1005][1005], which should not give any error, idk why it was giving WA but when i increased my array size to [3005][3005],it was working fine how is this possible?
I don’t understand this, is the question statement wrong? ll arr[1005][1005];
void calc()
{
ll i=0;
ll count=1;
for(int j=0;j<1005;j++)
{
ll k=j;
i=0;
while(i<1005 && k>=0)
{
arr[i][k]=count;
count++;
k–;
i++;
}
}
}
With this array, my code gives WA and if I just increase the size of array, it gives AC
Can someone tell me what is wrong here?
What am I doing wrong here, I checked a few possible outputs using the correct solutions and I m getting the same result, but code is not being accepted.
def value(m,n):
ans = ((m**2 - m +2) / 2) + (m*(n-1)) + (n*(n-1))/2
return int(ans)
t = int(input())
while t != 0:
x1,y1,x2,y2 = [int(x) for x in input().split()]
sum = 0
for i in range(0,y2-y1+1):
sum += value(x1,y1+i)
for i in range(1,x2-x1+1):
sum += value(x1+i,y2)
print(sum)
t = t-1
I want to ask if we create the matrix with the values in the same order and then we calculate sum by moving down and then right. Is this approach right or wrong?
pre-computing function run total operation 10^3*10^3 = 10^6
and we have time limit of 0.5 mean we can run only 10^4 operation approx.
so why not we are getting tle by precomputing the matrix?
Online judge does approx 10^8 operations in 1 second . So for 0.5 seconds it takes 5*10^7 ops which is more than our matrix precomputing function(10^6). That’s why we are not getting a TLE.