language: Java (sun-jdk-1.7.0_10)
date: 174 days 17 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.ArrayList;
import java.io.*;
 
class Lexicography {
 
    static ArrayList<Long> perms = new ArrayList<Long>();
 
    public static void main(String[] args) throws IOException{
        long time = System.currentTimeMillis();
        getPermutations(Integer.valueOf(new BufferedReader(new InputStreamReader(System.in)).readLine()));
 
        System.out.println("\nSize:-"+perms.size()+"\nTime:-"+(System.currentTimeMillis()-time));
        //This println is never printed... java aborts before that
    }
 
    public static ArrayList<Long> getPermutations(int num){
        int[] n = new int[num+1];
        for(int i=0; i<=num; i++) n[i]=i;
        perms.add(getLong(n));
        for(int i=num; i>=0; i--) permutate(n[i],n);
        return perms;
    }
 
    private static void permutate(int k, int[] n){
        if(k>n.length) return;
        int p=0;
        for(int i:n){ if(i==k) break; p++;}
 
        for(int i=0; i<n.length; i++){
            if(i==p || n[i]<k) continue;
            n=swap(p,i,n);
            perms.add(getLong(n));
            //System.out.println("i:"+(i+1)+" k:"+k+"    n:"+getLong(n));//this prints all permutations till the last one and then poof!
 
            for(int j=k-1; j>=0; j--) permutate(j,n);
            n=swap(p,i,n);
        }
    }
 
    private static int[] swap(int i, int f, int[] a){
        int t=a[f];
        a[f]=a[i]; a[i]=t;
        return a;
    }
 
    private static long getLong(int[] n){
        long ten=1, num=0;
        for(int i=n.length-1; i>=0; i--){
            num+=n[i]*ten; ten*=10;
        }
        return num;
    }
 
}
  • upload with new input
  • result: Runtime error     time: 0.27s    memory: 245760 kB     signal: -1

    9
    #
    # A fatal error has been detected by the Java Runtime Environment:
    #
    #  SIGSEGV (0xb) at pc=0xb70cb2ed, pid=27876, tid=3031939952
    #
    # JRE version: 6.0_31-b04
    # Java VM: Java HotSpot(TM) Client VM (20.6-b01 mixed mode, sharing linux-x86 )
    # Problematic frame:
    # V  [libjvm.so+0x3422ed]  MarkSweep::AdjustPointerClosure::do_oop(oopDesc**)+0xd
    #
    # An error report file with more information is saved as:
    # /tmp/hs_err_pid27876.log
    #
    # If you would like to submit a bug report, please visit:
    #   http://java.sun.com/webapps/bugreport/crash.jsp
    #