ARRT - Editorial

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

Can anyone please find out what’s wrong in my code.

firstly there can be atmost two minIdx and you are finding only one
Next you are trying to find minIdx without knowing the minimum value ,i.e you are finiding both
minIdx and maxv in the same loop withouth knowing the value you need. This seems to be a logical error.

If there is any mistake in my interpretation of your code please correct me.

can someone please tell me what’s wrong with my solution :
https://www.codechef.com/viewsolution/49349820

Out of bounds access on the following test input:

1
9
12 8 15 5 1 2 3 13 4
3 14 5 16 2 7 4 18 13
[simon@simon-laptop][07:53:02]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling rishabhpandey7-ARRT.cpp
+ g++ -std=c++14 rishabhpandey7-ARRT.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv -fno-sanitize-recover
rishabhpandey7-ARRT.cpp: In function ‘void solve()’:
rishabhpandey7-ARRT.cpp:39:12: warning: unused variable ‘rem’ [-Wunused-variable]
     ll int rem = inf;
            ^~~
+ set +x
Successful
[simon@simon-laptop][07:53:11]
[~/devel/hackerrank/otherpeoples]>echo "1                 
9
12 8 15 5 1 2 3 13 4
3 14 5 16 2 7 4 18 13
" | ./a.out
/usr/include/c++/7/debug/vector:417:
Error: attempt to subscript container with out-of-bounds index 10, but 
container only holds 9 elements.

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

This line, according to gdb:

if ( (a[1]+b[ans3+1] && ans3+1<n)%n < (a[1]+b[ans+1] && ans+1<n)%n){

@ssjgz can you please elaborate why the output for the test case you mentioned

gives output

and not

And two possible index of b are ( 1 based ) 2 ang 8 .

This should explain everything you need.

I don’t understand your question :slight_smile: The correct answer for that testcase, as far as I can tell, is

1 1 5 4 6 1 6 
1 Like

I have red the editorial sir , I have a small confusion for this test case hence approached to get it cleared .

ok , but when i run code as given by the author on this test case it gives the output

So , is the author’s code wrong ?

Dunno - the Editorialist and the Setter’s code gives 1 1 5 4 6 1 6 5.

@prasant21 the code given by you gives wrong output for the test case

The output should be

but your code gives

Hey @cherry0697 , it looks like Tester’s and Editorialist’s solutions are not correct.

Edit: Maybe, Author’s solution is wrong.

They are failing for this test case as mentioned by @ssjgz .

Input

1
8
14 11 10 4 7 1 13 16
14 11 8 15 16 1 5 3

Output (from Author’s solution)

1 1 1 4 0 6 0 6

Output from Tester’s and Editorialist’s solutions

1 1 5 4 6 1 6 5 

Maybe I’m misunderstanding (I didn’t do this Problem either, and maybe the testcase is invalid?), but it seems like it’s actually the authors that is wrong:

[simon@simon-laptop][08:26:06]
[~/devel/hackerrank/otherpeoples]>echo "1
8
14 11 10 4 7 1 13 16
14 11 8 15 16 1 5 3" | ./a.out       
B: 
14 11 8 15 16 1 5 3 
c: 
4 6 2 3 7 2 2 3 
New best!
B: 
11 8 15 16 1 5 3 14 
c: 
1 3 1 4 0 6 0 6 
New best!
B: 
8 15 16 1 5 3 14 11 
c: 
6 2 2 5 4 4 3 3 
B: 
15 16 1 5 3 14 11 8 
c: 
5 3 3 1 2 7 0 0 
B: 
16 1 5 3 14 11 8 15 
c: 
6 4 7 7 5 4 5 7 
B: 
1 5 3 14 11 8 15 16 
c: 
7 0 5 2 2 1 4 0 
B: 
5 3 14 11 8 15 16 1 
c: 
3 6 0 7 7 0 5 1 
B: 
3 14 11 8 15 16 1 5 
c: 
1 1 5 4 6 1 6 5 
New best!
1 1 5 4 6 1 6 5 

It is a valid input. Elements in both sequences lie in the range [1, 2\times N] viz., [1, 16]. The elements are unique too.

1 Like

This is my original solution , https://www.codechef.com/viewsolution/49241322. I didn’t authored that java code.
pastebin link : #include<bits/stdc++.h>using namespace std;#define ll long long#define end - Pastebin.com

@ssjgz ( sorry for the ping ) can you please check this code , it give correct output for all your test cases and that mentioned in the question but it still give WA on system test , if i miss something.

1
9
12 8 15 5 1 2 3 13 4
3 14 5 16 2 7 4 18 13
1 Like

I don’t know why it’s showing out of bounds… But my code is working fine on my pc and on online gdb… Maybe it’s failing on some other test case… But it is working fine for the test case given by you.