ARRT - Editorial

what does the term " pairwise distinct elements " means . Cant it simply be " distinct " ?
Or its just for confusing ?

2 Likes

It means if we take any two numbers from the array it should not be same

can anyone help me with my code
https://www.codechef.com/viewsolution/49364362

Consider the test input:

1
2
2 1
2 4

Hey @cherry0697 could you please help me with the solution of mine it’s giiving WA but I am trying to do the exact same thing.
Solution link : CodeChef: Practical coding for everyone

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