MARM - Editorial

For the testcase:

1
4 49
858 723 332 138 

your program is giving (Edit: actually, I’m getting a different result every time, so there’s some Undefined Behaviour/ uninitialised data in there):

140725646481792 4 2 94828364422956 

when it should be:

976 723 332 138

so how can i correct my solution by keeping the same approcah of dp

I don’t know :slight_smile: Why do you want to use DP instead of the method described in the Editorial?

just trying an another way

1 Like

Could u check why my my output is giving wrong ans:
i just observed the patters that after three operations the array retains the same confiquration.
import java.util.;
import java.io.
;
import java.lang.*;

class cd207
{
public static void main(String args[])throws IOException
{
try
{
//takign input through IO
InputReader in = new InputReader(System.in);
OutputWriter out = new OutputWriter(System.out);
int t = in.readInt(),n,rep,rem;
long k;
while(t–>0)
{
n = in.readInt();
k = in.readLong();
int arr[] = IOUtils.readIntArray(in,n);
rem = (int)k%n;
rep = (int)k/n;
if(rep!=0)
{
op(arr,rem,rep%3);
}
else
{
for(int i=0;i<k;i++)
arr[i] = arr[i]^arr[arr.length-i-1];
}
for(int i=0;i<arr.length;i++)
{
out.print(arr[i]+" ");
out.flush();
}
out.printLine();
out.flush();
}
out.close();
}
catch(Exception e){
e.printStackTrace();
}

}

static void op(int arr[],int rem,int cat)
{
	int n = (arr.length-1)/2;
	switch(cat)
	{
		case 0 : 
					
					for(int i=0;i<=n;i++)
						arr[i] = arr[i]^arr[arr.length-i-1];
					for(int i=n+1;i<arr.length;i++)
						arr[i] = 0;
					break;
		
		case 1 :
					
				for(int i=0;i<arr.length;i++)
					arr[i] = arr[i]^arr[arr.length-i-1];
					break;
		
		case 2:
				for(int i=0;i<=n;i++)
					arr[i] = 0;
				for(int i=n+1;i<arr.length;i++)
					arr[i] = arr[i]^arr[arr.length-i-1];
					break;
		default:		
		
	}
	
	for(int i=0;i<rem;i++)
		arr[i] = arr[i]^arr[arr.length-i-1];
}

}

Please either format your code or link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

https://www.codechef.com/viewsolution/27154577
check it here :slight_smile:

1 Like

It also fails the testcase here:

Can someone please tell me where my code gone wrong.

It fails on the following testcase:

1
91 27
458 406 299 653 253 660 551 56 174 880 194 660 141 945 790 667 949 365 798 146 818 473 545 90 271 572 615 907 565 505 233 22 262 884 26 514 543 576 570 716 807 115 727 948 411 869 966 711 233 115 857 402 588 401 491 210 972 105 116 536 961 701 910 574 584 935 440 478 863 9 193 669 475 272 968 237 140 933 947 372 48 803 126 987 204 616 196 527 73 663 415 

The answer should be:

85 769 354 130 57 252 747 995 208 83 242 992 830 20 922 630 125 125 709 527 1011 464 382 388 183 411 47 907 565 505 233 22 262 884 26 514 543 576 570 716 807 115 727 948 411 869 966 711 233 115 857 402 588 401 491 210 972 105 116 536 961 701 910 574 584 935 440 478 863 9 193 669 475 272 968 237 140 933 947 372 48 803 126 987 204 616 196 527 73 663 415 

Can anyone please explain the logic of Alternate solution

Why do we do this, can someone help me understsnd this?

I can’t understand what this line is doing. For eg - If N=13 and K=45 which satisfies the case K>3N, then k = k%(3n) + 3n simply gives back the same value of k. Please explain.

This is when k becomes as large as 10^{12}

Then 3*n would still be much better than 10^{12} but for lower values it’s okay if it’s just the same.

You getting my point?

1 Like

Hey guys, can anyone take a look at my code and figure out where am i going wrong.
https://www.codechef.com/viewsolution/27531108

How big can K be? What’s the highest number an int can hold?

Can anybody tell me how we conclude this ?

Solution 2: We simply let K\gets K\bmod 3NK←Kmod3N and do what we’re told to do. When NN is odd, we need to deal with A[\frac{N-1}{2}]A[
2
N−1

] as a special case, though.

:sweat_smile:I was too lost in the logic

1 Like

Really GREAT!!!

Can any one explain why the 3N logic actually work?:thinking: