CSES - Putka Open 2015 – 4/6 - Results
Submission details
Task:Taulukot
Sender:
Submission time:2015-10-09 22:34:25 +0300
Language:Java
Status:READY
Result:55
Feedback
groupverdictscore
#1ACCEPTED26
#2ACCEPTED29
#30
Test results
testverdicttimegroup
#1ACCEPTED0.18 s1details
#2ACCEPTED0.17 s1details
#3ACCEPTED0.17 s1details
#4ACCEPTED0.17 s1details
#5ACCEPTED0.17 s1details
#6ACCEPTED0.17 s2details
#7ACCEPTED0.17 s2details
#8ACCEPTED0.17 s2details
#9ACCEPTED0.17 s2details
#10ACCEPTED0.18 s2details
#11--3details
#12--3details
#13--3details
#14--3details
#15--3details

Code

//package alkuluvut;

/**
 *
 * @author Adreno
 */
public class Alkuluvut {

    public static boolean[] tarkistettu;
    public static boolean[] onAlkuLuku;
            
    public static void main(String[] args) {
        IO io = new IO();
        int n = io.nextInt();
        tarkistettu = new boolean[n+n+5];
        onAlkuLuku = new boolean[n+n+5];
        boolean[] kaytettyA = new boolean[n+1];
        boolean[] kaytettyB = new boolean[n+1];
        int pointer = 0;
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i=n; i>=1; i--) {
            if (kaytettyA[i] && kaytettyB[i]) continue;
            for (int j=i; j>=1; j--) {
                if ((kaytettyA[i] || kaytettyB[j]) && (kaytettyA[j] || kaytettyB[i])) continue;
                if (!onkoAlkuluku(i+j)) continue;
                if (!kaytettyA[i] && !kaytettyB[j]) {
                    kaytettyA[i] = true;
                    kaytettyB[j] = true;
                    a[pointer] = i;
                    b[pointer] = j;
                    pointer++;
                }
                if (!kaytettyA[j] && !kaytettyB[i]) {
                    kaytettyA[j] = true;
                    kaytettyB[i] = true;
                    a[pointer] = j;
                    b[pointer] = i;
                    pointer++;
                } 
            }
        }
        
        for (int i=0; i<n; i++) io.print(a[i] + " ");
        io.println();
        for (int i=0; i<n; i++) io.print(b[i] + " ");
        io.println();
        
        io.close();
    }
    
    public static boolean onkoAlkuluku(int a) {
        if (tarkistettu[a]) return onAlkuLuku[a];
        tarkistettu[a] = true;
        for (int i=2; i*i<=a; i++) {
            if (a%i == 0) return false;
        }
        onAlkuLuku[a] = true;
        return true;
    }
    
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
1

correct output


user output


Test 2

Group: 1

Verdict: ACCEPTED

input
4

correct output
1 2 3 4 
2 1 4 3 

user output
4 3 2 1 
3 4 1 2 

Test 3

Group: 1

Verdict: ACCEPTED

input
5

correct output
1 2 3 4 5 
1 5 4 3 2 

user output
5 2 4 3 1 
2 5 3 4 1 

Test 4

Group: 1

Verdict: ACCEPTED

input
8

correct output
1 2 3 4 5 6 7 8 
2 1 4 3 8 7 6 5 

user output
8 5 7 6 4 3 2 1 
5 8 6 7 3 4 1 2 

Test 5

Group: 1

Verdict: ACCEPTED

input
9

correct output
1 2 3 4 5 6 7 8 9 
1 5 4 3 2 7 6 9 8 

user output
9 8 7 6 5 2 4 3 1 
8 9 6 7 2 5 3 4 1 

Test 6

Group: 2

Verdict: ACCEPTED

input
77

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
77 74 76 75 73 66 72 67 71 68 ...

Test 7

Group: 2

Verdict: ACCEPTED

input
70

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
70 69 68 63 67 64 66 65 62 51 ...

Test 8

Group: 2

Verdict: ACCEPTED

input
72

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
72 67 71 68 70 69 66 65 64 63 ...

Test 9

Group: 2

Verdict: ACCEPTED

input
86

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
86 81 85 82 84 83 80 77 79 78 ...

Test 10

Group: 2

Verdict: ACCEPTED

input
68

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
68 63 67 64 66 65 62 51 61 52 ...

Test 11

Group: 3

Verdict:

input
90764

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Test 12

Group: 3

Verdict:

input
97976

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Test 13

Group: 3

Verdict:

input
96762

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Test 14

Group: 3

Verdict:

input
94823

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Test 15

Group: 3

Verdict:

input
91479

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)