Can we solve this question by using char array and not by using vector,map etc.

i have solve it but i got partially correct.

my code

Can we solve this question by using char array and not by using vector,map etc.

i have solve it but i got partially correct.

my code

Hi @goku_11,

I think that your code should have:

```
char a[10**9][10**9]={'\0'};
```

This is because n,m according to the constraints are within the range 1 <= n,m <= 10^9

I donâ€™t know if this will result in a TLE or any other error. (donâ€™t know about memory handling)

If it works, please do let me know.

Cheers

Aadarshâ€¦

I guess you are getting partially correct because you are trying to access something out of bound or something related to memory. Iâ€™m not sure of it, though, I think if you solve this problem using structures it will be better.

Even I had the same problem at first because of using a 2d array to store data. This fetched me partially correct answer. but then I Improved of some better logic and got AC.

My first solution- (30 points)- using array-https://www.codechef.com/viewsolution/23825674

My second solution (70 points+30 points)- Using class(structure)- https://www.codechef.com/viewsolution/23854861

Your logic is correct, but using a matrix is not feasible, as matrix as big as [10^9][10^9] will blow up the memory and time limits

Try using an efficient approach and check the editorial

a[10**9][10**9] memory size you can not be use because their had limit is given for memory 500000 bytes and your array use more space .

you need to create size of a[k][2] .

this problem can be solve using only array use donâ€™t need to use map/vector

simply create a[k][2] size array

link:

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

finally solved it using simple two simple operations

binary search and quick sort

simple implementation using C

Can anyone tell me why this solution gives AC for subtask 2 but not for 1? What I am doing is calculating the sum on the fly by -

- storing each input plantâ€™s position in a hashmap
- starting with a fence value of 4, subtracting 2 for every plant found on its sides (which is done by checking if there is a key for those positions in the hashmap)
- adding the final value to the sum

This seems like a good solution but since itâ€™s failing, I think the logic is wrong somewhere.

As I mentioned above, I didnâ€™t know about memory handling and time limits in C++. I also tried to use a matrix-like structure but resulted in TLE for the 2nd subtask. So, I used a dictionary data structure to store the co-ordinates for easy access (something similar to yours.

My code: https://www.codechef.com/viewsolution/23833436

Cheers

Aadarshâ€¦

@ubc_123 Nice solution. What is the logic behind the solution? What does matrix[i] contain?