Submission details
Task:Counting Canals
Sender:thierry
Submission time:2018-09-13 18:38:18 +0300
Language:Java
Status:READY
Result:
Test results
testverdicttime
#10.14 sdetails
#20.14 sdetails
#30.14 sdetails
#40.14 sdetails
#50.15 sdetails
#60.14 sdetails
#70.14 sdetails
#80.14 sdetails
#90.14 sdetails
#100.15 sdetails
#110.54 sdetails
#120.55 sdetails
#130.53 sdetails
#140.54 sdetails
#150.54 sdetails
#160.53 sdetails
#170.53 sdetails
#180.54 sdetails
#190.54 sdetails
#200.54 sdetails
#210.53 sdetails
#220.53 sdetails
#230.54 sdetails
#240.54 sdetails
#250.54 sdetails
#260.53 sdetails
#270.54 sdetails
#280.54 sdetails
#290.54 sdetails
#300.54 sdetails

Code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Viikko2e {

    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) {

        FastReader s = new FastReader();
        int n = s.nextInt();

        int[][] sudoku = new int[n][n];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int a = s.nextInt();
                if (a > n) {
                    System.out.println("NO");
                    break;
                }
                sudoku[i][j] = a;
            }
        }

        if (tarkista(n, sudoku)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }

    private static boolean tarkista(int n, int[][] sudoku) {
        Set<Integer> setti = new HashSet<>();
        
        for (int i = 0; i < n; i++) {
            for (int j = 0; i < n; i++) {
                int a = sudoku[i][j];
                if (setti.contains(a)) {
                    return false;
                }
                setti.add(a);
            }
            setti.clear();
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; i < n; i++) {
                int a = sudoku[j][i];
                if (setti.contains(a)) {
                    return false;
                }
                setti.add(a);
            }
        }
        return true;
    }
}

Test details

Test 1

Verdict:

input
5
1 2
2 3
3 4
4 5

correct output
15

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at java.base/java.util.StringTo...

Test 2

Verdict:

input
4
3 2
2 1
4 2

correct output
9

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at java.base/java.util.StringTo...

Test 3

Verdict:

input
1

correct output
1

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at java.base/java.util.StringTo...

Test 4

Verdict:

input
6
1 3
3 5
3 4
4 6
...

correct output
17

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at java.base/java.util.StringTo...

Test 5

Verdict:

input
10
10 1
1 9
9 2
2 8
...

correct output
19

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at java.base/java.util.StringTo...

Test 6

Verdict:

input
10
10 6
2 4
1 2
5 10
...

correct output
25

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at java.base/java.util.StringTo...

Test 7

Verdict:

input
10
9 1
8 1
8 5
10 2
...

correct output
20

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at java.base/java.util.StringTo...

Test 8

Verdict:

input
10
9 5
1 6
8 5
10 6
...

correct output
24

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at java.base/java.util.StringTo...

Test 9

Verdict:

input
10
10 3
1 6
6 3
10 8
...

correct output
26

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at java.base/java.util.StringTo...

Test 10

Verdict:

input
10
1 10
9 3
5 10
6 8
...

correct output
22

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at java.base/java.util.StringTo...

Test 11

Verdict:

input
100000
61825 85829
24480 90462
1014 5496
81225 44931
...

correct output
3130799

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 12

Verdict:

input
100000
12328 59847
68010 51200
20911 42026
5769 15416
...

correct output
13958274

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 13

Verdict:

input
100000
20362 12728
7958 63236
52010 30403
43065 57339
...

correct output
15065805

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 14

Verdict:

input
100000
8572 72714
94149 74894
64167 42479
28114 53008
...

correct output
365273

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 15

Verdict:

input
100000
1978 36216
32844 35606
89082 19460
32960 67705
...

correct output
299957

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 16

Verdict:

input
100000
1 100000
2 100000
2 99999
3 99999
...

correct output
199999

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 17

Verdict:

input
100000
1 2
2 3
3 4
4 5
...

correct output
5000050000

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 18

Verdict:

input
100000
26026 17578
2063 27495
18825 88516
73417 44243
...

correct output
300106

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 19

Verdict:

input
100000
62594 92916
39396 77445
39736 18145
51960 63921
...

correct output
305292

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 20

Verdict:

input
100000
35361 29834
80103 20628
56121 98538
96141 60130
...

correct output
299953

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 21

Verdict:

input
100000
83387 6566
1464 36071
83940 1947
30207 81630
...

correct output
18170796

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 22

Verdict:

input
100000
57048 59591
13592 7630
96625 65606
39702 62144
...

correct output
122357921

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 23

Verdict:

input
100000
665 16956
97424 82744
19070 82235
29207 21317
...

correct output
255370837

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 24

Verdict:

input
100000
73391 7794
48957 7794
10376 7794
68812 7794
...

correct output
661409588

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 25

Verdict:

input
100000
25428 93716
47665 20024
43005 47665
47665 4035
...

correct output
775090231

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 26

Verdict:

input
100000
88514 75301
20924 75301
8871 75301
26360 75301
...

correct output
1860034699

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 27

Verdict:

input
100000
31831 1
46505 1
76032 1
41560 1
...

correct output
199999

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 28

Verdict:

input
100000
38156 15310
92580 66280
10847 49530
8672 38794
...

correct output
27926764

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 29

Verdict:

input
100000
60300 13490
372 28166
4123 3653
97935 79942
...

correct output
27607584

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...

Test 30

Verdict:

input
100000
93798 40604
95227 14928
80126 98198
54474 67913
...

correct output
22603373

user output
(empty)

Error:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at Viikko2e.main(V...