Help needed in MIN MAX STRING

are you sure about v.size() never exceeds 3 * 10^5 in hashi[v.size()]

I think so ,because total no. Of queries are 2 * 10 ^ 5 and N is <10 ^ 4 so actually it should not even exceed 2 * 10^5+10^4

1 Like

yes my bad i didn’t see that.

1 Like

i think experts need to take over this problem. :sweat_smile:
@ssjgz help him if you can.

2 Likes
[simon@simon-laptop][20:54:46]
[~/devel/hackerrank/otherpeoples]>g++ -std=c++14 dhruv788-MINMXSTR.cpp -O3 -g3 -Wall -Wextra -DONLINE_JUDGE -D_GLIBCXX_DEBUG    -fsanitize=undefined -ftrapv
dhruv788-MINMXSTR.cpp: In function ‘std::__debug::vector<long long int> hashed(std::__cxx11::string&, int)’:
dhruv788-MINMXSTR.cpp:25:34: warning: unused parameter ‘l’ [-Wunused-parameter]
 vector<lli> hashed(string &s,int l)
                                  ^
dhruv788-MINMXSTR.cpp: In function ‘int main()’:
dhruv788-MINMXSTR.cpp:83:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     if((it->first).size()>r)
                        ~~~~~~~~~~~~~~~~~~^~
[simon@simon-laptop][20:54:58]
[~/devel/hackerrank/otherpeoples]>echo "1                                                                                                   
3
abcdef
abc
xyz
6
1 2 d
2
3
1 4 c
2
3 " | ./a.out
dhruv788-MINMXSTR.cpp:22:9: runtime error: index 200001 out of bounds for type 'long long int [200001]'
dhruv788-MINMXSTR.cpp:22:10: runtime error: store to address 0x5592db5dc668 with insufficient space for an object of type 'lli'
0x5592db5dc668: note: pointer points here
 0f 16 13 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
              ^ 
1
3
5
3
1 Like

What does it mean? :sweat_smile: Is it that memory limit is exceeded as we can’t store an array of long long int of size 2*10^5

Precisely what it says: on line 22, you are attempting to access the element at index 200001 in array with only 200001 values (array indexing is 0-relative, remember!) :slight_smile:

No :slight_smile:

3 Likes

i knew that some out of bounds access is there but couldn’t figure that out thats why we have people like you :upside_down_face:

I changed it , but it is still showing the same result , and BTW Thanks

Yeah , @aneee004 @galencolin @humane @everule1 @akshitm16 @carre @swapnil159
Want to seek your help as well

Link is updated , help is required,please help😅

Your poweri array is too small. Have at least size 4*10^5, because the maximum size of string can be 2*10^5, and then there are 2*10^5 queries after that.

1 Like

Ok , thanks for the help, but it is still showing the same error.

I have found a random test case on which it fails , but i am not able to understand why it fails more accurately it is not taking the x for the 4th query can someone please explain why. Here is the random testcase I generated.
1
3
abcdefaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
abcaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
xyz
6
1 2 d
2
3
1 3 c
2
3

With this solution:

[simon@simon-laptop][22:13:32]
[~/devel/hackerrank/otherpeoples]>g++ -std=c++14 dhruv788-MINMXSTR.cpp -O3 -g3 -Wall -Wextra -DONLINE_JUDGE -D_GLIBCXX_DEBUG    -fsanitize=undefined -ftrapv
dhruv788-MINMXSTR.cpp: In function ‘std::__debug::vector<long long int> hashed(std::__cxx11::string&, int)’:
dhruv788-MINMXSTR.cpp:25:34: warning: unused parameter ‘l’ [-Wunused-parameter]
 vector<lli> hashed(string &s,int l)
                                  ^
dhruv788-MINMXSTR.cpp: In function ‘int main()’:
dhruv788-MINMXSTR.cpp:83:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     if((it->first).size()>r)
                        ~~~~~~~~~~~~~~~~~~^~
[simon@simon-laptop][22:13:43]
[~/devel/hackerrank/otherpeoples]>echo "1                                                                                                 
3
abcdefaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
abcaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
xyz
6
1 2 d
2
3
1 3 c
2
3" | ./a.out
4
3
/usr/include/c++/7/debug/vector:417:
Error: attempt to subscript container with out-of-bounds index 3, but 
container only holds 0 elements.

Objects involved in the operation:
    sequence "this" @ 0x0x55721803bf28 {
      type = std::__debug::vector<long long, std::allocator<long long> >;
    }
Aborted (core dumped)
1 Like

can you explain this one as well and also tell which IDE you use .
you can also explain with the below test case as well as (any one would be sufficient) it too fails on same condition.
1
3
abcdefa
abca
xyz
6
1 2 d
2
3
1 3 c
2
3

I just use gcc on the command-line :slight_smile:

You now have a 100% reproducible testcase, and the compiler-flags needed to expose the error in your code; use gdb to debug it :slight_smile:

1 Like

which line?
“You now have a 100% reproducible testcase, and the compiler-flags needed to expose the error in your code; use gdb to debug it :slight_smile:
ok,Thanks

But can you please still tell why it is not taking x as input in the 4th test case

https://www.codechef.com/viewsolution/36686753
please help me in this code this done by using hashing but getting tle