POSAND - Editorial

Before passing comments, you could have at least made the efforts for reading the problem statement carefully. The problem statement said: " A permutation p1,p2…pN is beautiful if pi&pi+1 is greater than 0 for every 1≤i<N . You are given an integer N, and your task is to construct a beautiful permutation of length N or determine that it’s impossible".

So as per this, for N=1, the sequence {1} does not satisfy the condition for being a beautiful permutation.

While what you say would have been correct if the problem statement mentioned: “A permutation p1,p2…pN is not beautiful if pi&pi+1 is equal to 0 for any 1≤i<N . You are given an integer N, and your task is to construct a beautiful permutation of length N or determine that it’s impossible”

I read the statement many times during the contest. Thought a lot on where I was going wrong and only then I posted here. Judging people and passing comments is very easy. Let me tell you that this platform is for enjoying the sport of competitive programming and problem solving not for pointing fingers at one another. Setters and testers can also make mistakes. After all they are humans.

2 Likes

No. You are twisting the words of the problem statement. The problem statement was this : A permutation p1,p2…pN is beautiful if pi&pi+1 is greater than 0 for every 1≤i<N . You are given an integer N, and your task is to construct a beautiful permutation of length N or determine that it’s impossible.
So it is beautiful if and only if pi&pi+1 > 0 for all valid i, which is clearly not the case for N=1.

I totally agree with the point that Setters and Testers can also make mistakes. And also that the platform is for enjoying the Sport of Competitive Programming.

I read your previous comment and gave my 2 cents on it. The thing that I didn’t like in the first place was that you were too certain of the mistake from the writers and testers. Your comment didn’t seem open to reasoning at all. I see this pattern among a lot of other comments, a good portion of them were made without understanding the problem properly.

Having said that, I apologize that I judged your comment with the same parameter. I didn’t intend to point fingers at you or at anybody else. Peace.

Coming to the Statement, upon reading it again, I agree that it could’ve been worded in a better way The statement does look ambiguous when N is 1.

What I am surprised more about is that why didn’t you just tried submitting multiple times with two different answers for that particular case during the contest?

During the contest, all I received was a partial correct verdict. I was not sure of what was going wrong with my logic. I thought that my main underlying logic itself is faulty. I thought that I was missing some corner case that I wasn’t thinking about. I didn’t even consider the N=1 case, because that did not seem to make sense given the conditions of the problem. So I just got away with the problem, and waited till the end of the contest. After the contest, when I read the discussions going on related to the problem I realized that my code was failing due to the N=1 case. To confirm it, I resubmitted my code by adding the N=1 condition, and it ended up getting an AC verdict. This did not make sense to me. So I went again to read the problem statement, and the N=1 case was not fitting the problem statement. After all this, I posted it in the discussion here. Probably I should have worded my comments in a manner which was open to suggestions, but I did not realize it at that point. Sorry for that.

1 Like

I agree. Even, I have recieved partial marks in this question, and during the contest, I tried to submit the solution by making different tweak each time in my logic, but I never thought that N = 1 will return 1 not -1.

If there is option to downvote this question, I would have done that.

I think that the statement was not clear enough about this case. I asked about this in the problem statement’s comment section in division B, but got no reply…

Hello I am getting only one(First) test case fail,remaing all are pass
please let me know the issue
CodeChef: Practical coding for everyone

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/*

  • To change this license header, choose License Headers in Project Properties.

  • To change this template file, choose Tools | Templates

  • and open the template in the editor.
    /
    /
    *

  • @author samuel.jawahar
    */
    public class Main {

    private static boolean isPowerOf2(int k) {

     if (k == 1 || k == 2 || k == 4 || k == 8 || k == 16 || k == 32 || k == 64 || k == 128 || k == 256 || k == 512 || k == 1024 || k == 2048 || k == 4096 || k == 8192 || k == 16384 || k == 32768 || k == 65536) {
         return true;
     }
    
     return false;
    

    }

    public static void main(String[] args) {
    try {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int t = Integer.parseInt(br.readLine());
    StringBuilder sb = new StringBuilder();
    int nextVal = 0;
    String result = " ";

         for (int i = 0; i < t; i++) {
             result = " ";
             sb.delete(0, sb.capacity());
             int n = Integer.parseInt(br.readLine());
    
             if (n == 1) {
                 System.out.println("1");
                 continue;
             }
             if (n == 3) {
                 System.out.println("1 3 2");
                 continue;
             }
             if (n == 5) {
                 System.out.println("2 3 1 5 4");
                 continue;
             }
             if (n == 2 || n == 4 || n == 8) {
                 System.out.println("-1");
                 continue;
             }
             if (isPowerOf2(n)) {
                 System.out.println(-1);
                 continue;
             }
             sb.append("2 3 1 5 4 ");
             for (int j = 6; j <= n; j++) {
                 if (isPowerOf2(j)) {
                     if (j + 1 <= n) {
                         nextVal = j + 1;
                         sb.append(nextVal).append(" ");
                     } 
                     sb.append(j).append(" ");
                     if (j + 2 <= n) {
                         nextVal = j + 2;
                         sb.append(nextVal).append(" ");
                         j = nextVal;
                     } else {
                         break;
                     }
                 } else {
                     sb.append(j).append(" ");
                 }
             }
    
             result = sb.toString().trim();
             System.out.println(result);
             sb.delete(0, sb.capacity());
         }
     } catch (IOException ex) {
    
     }
    

    }
    }


I am not sure why t gives partially correct answer for me can someone help!

My Code

Can anyone tell the edge cases where my code is giving wrong answer :slight_smile:
partial solution link

@jawa2code Same here. My code is passing all test cases except the first one. Don’t know where I am getting wrong. My java code : CodeChef: Practical coding for everyone
Please tell me if you can find a solution to the problem.

1 Like

if input has space character at the end or beginning , parseInt( ) throws run-time error. using trim() helps

for n = 1 ans will be 1 because if p(i) and p(i+1) exist both then only their bitwise and should be positive but here only p(1) exist and p(2) don’t exist ,so no need of them to be positive
.

1 Like

why i am getting RE (NZEC) for 1 case? remaing all are passed
https://www.codechef.com/viewsolution/38863965

Thanks angel1 after using trim() all test are cleared

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t–>0)
{
int n=sc.nextInt();
if(n==1)
System.out.println(“1”);
else if((n&(n-1))==0)
System.out.println(“-1”);
else
{
System.out.print("2 3 1 “);
for(int i=4;i<=n;i++)
{
if((i&(i-1))==0)
{
System.out.print(i+1+” “+i+” “);
i++;
}
else
System.out.print(i+” ");
}
System.out.println();
}
}// your code goes here
}
}

Can anyone please tell why my code is giving a TLE for the 3rd task of the second subtask, for the rest its giving AC verdict except this one.

the 1 case has un necessary space because of that my 1st test case failed

naman_bansal:but they gave the un nessasry space in the input thats why my 1st case has failed.CodeChef: Practical coding for everyone
just by removing the space from input all test cases are correct
CodeChef: Practical coding for everyone

Just missed ,
if(n==1)
{
cout<<1<<"\n";
}
and it gives partial result for me. :no_mouth:

why am i getting WA
my soln : CodeChef: Practical coding for everyone
question:POSAND Problem - CodeChef

why am i getting WA
my soln : Solution: 41463928 | CodeChef
question:Contest Page | CodeChef