You are not logged in. Please login at www.codechef.com to post your questions!

×

Wrong Answer in Permutation Shuffle

Can someone explain why this code in JAVA gives WA?

import java.io.; import java.util.; class Permshuff { public static void main(String [] args) { InputReader1 reader = new InputReader1(System.in); PrintWriter out=new PrintWriter(System.out); int t=reader.nextInt(); while(t-->0) { int n=reader.nextInt(); int m=reader.nextInt(); boolean flag=true; Integer a[]=new Integer[n]; for(int i=0;i<n;i++) a[i]="reader.nextInt();" while(m--="">0) { int from=reader.nextInt(); int to=reader.nextInt(); Arrays.sort(a,from-1,to); } for(int i=0;i<n;i++) { if(a[i]!=i+1) { flag=false; break; } } if(flag) out.println("Possible"); else out.println("Impossible"); out.flush(); } out.close(); } } class InputReader1 {

private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;

public InputReader1(InputStream stream) {
    this.stream = stream;
}

public int read() {
    if (numChars == -1)
        throw new InputMismatchException();
    if (curChar >= numChars) {
        curChar = 0;
        try {
            numChars = stream.read(buf);
        } catch (IOException e) {
            throw new InputMismatchException();
        }
        if (numChars <= 0)
            return -1;
    }
    return buf[curChar++];
}

public int nextInt() {
    int c = read();
    while (isSpaceChar(c))
        c = read();
    int sgn = 1;
    if (c == '-') {
        sgn = -1;
        c = read();
    }
    int res = 0;
    do {
        if (c < '0' || c > '9')
            throw new InputMismatchException();
        res *= 10;
        res += c & 15;
        c = read();
    } while (!isSpaceChar(c));
    return res * sgn;
}

public long nextLong() {
    int c = read();
    while (isSpaceChar(c))
        c = read();
    int sgn = 1;
    if (c == '-') {
        sgn = -1;
        c = read();
    }
    long res = 0;
    do {
        if (c < '0' || c > '9')
            throw new InputMismatchException();
        res *= 10;
        res += c & 15;
        c = read();
    } while (!isSpaceChar(c));
    return res * sgn;
}

public String next() {
    int c = read();
    while (isSpaceChar(c))
        c = read();
    StringBuilder res = new StringBuilder();
    do {
        res.appendCodePoint(c);
        c = read();
    } while (!isSpaceChar(c));
    return res.toString();
}

public String nextLine() {
    int c = read();
    //while (c != '\n' && c != '\r' && c != '\t' && c != -1)
    //c = read();
    StringBuilder res = new StringBuilder();
    do {
        res.appendCodePoint(c);
        c = read();
    } while (c != '\n' && c != '\r' && c != '\t' && c != -1);
    return res.toString();
}

public static boolean isSpaceChar(int c) {
    return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}

}

asked 03 Nov '14, 23:46

animesh_f's gravatar image

6★animesh_f ♦
8831422
accept rate: 9%

edited 08 Jan '15, 15:54

admin's gravatar image

0★admin ♦♦
19.8k350498541


Can you read this and try to ask again?

link

answered 04 Nov '14, 03:06

betlista's gravatar image

3★betlista ♦♦
16.9k49115225
accept rate: 11%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,313
×1,070
×856
×801
×183

question asked: 03 Nov '14, 23:46

question was seen: 1,059 times

last updated: 08 Jan '15, 15:54