CSES - Datatähti 2023 alku - Results
Submission details
Task:Ruudukko
Sender:andreibe
Submission time:2022-10-31 11:56:18 +0200
Language:Java
Status:READY
Result:61
Feedback
groupverdictscore
#1ACCEPTED28
#2ACCEPTED33
#30
Test results
testverdicttimegroup
#1ACCEPTED0.08 s1, 2, 3details
#2ACCEPTED0.08 s1, 2, 3details
#3ACCEPTED0.08 s1, 2, 3details
#4ACCEPTED0.13 s2, 3details
#5ACCEPTED0.15 s2, 3details
#6ACCEPTED0.15 s2, 3details
#7ACCEPTED0.93 s3details
#8--3details
#9--3details

Code

//package com.patonki;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;

class Pair implements Comparable<Pair>{
    int value;
    int y;
    int x;

    public Pair(int value, int y, int x) {
        this.value = value;
        this.y = y;
        this.x = x;
    }

    @Override
    public int compareTo(Pair o) {
        int val = Integer.compare(value,o.value);
        if (val != 0) return val;

        int y = Integer.compare(this.y,o.y);
        if (y != 0) return y;

        return Integer.compare(x,o.x);
    }

    @Override
    public String toString() {
        return "Pair{" +
                "value=" + value +
                ", y=" + y +
                ", x=" + x +
                '}';
    }
}
public class Lol {
    static long[][] d = new long[1010][1010];
    static int M = 1000000007;
    static long[] rivit = new long[1010];
    static long[] kolumnit = new long[1010];


    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("lol.txt")));
        int n = Integer.parseInt(reader.readLine());

        TreeSet<Pair> pairs = new TreeSet<>();
        for (int y = 0; y < n; y++) {
            String[] rivi = reader.readLine().split(" ");
            for (int x = 0; x < rivi.length; x++) {
                int val = Integer.parseInt(rivi[x]);
                pairs.add(new Pair(val,y,x));
            }
        }
        int curnumber = pairs.first().value;
        ArrayList<Pair> toedit = new ArrayList<>();
        //System.out.println(pairs);
        for (Pair pair : pairs) {

            int y = pair.y;
            int x = pair.x;
            int value = pair.value;
            if (value != curnumber) {
                for (Pair p : toedit) {
                    rivit[p.y] += d[p.y][p.x];
                    rivit[p.y] %= M;
                    kolumnit[p.x] += d[p.y][p.x];
                    kolumnit[p.x] %= M;
                }
                toedit.clear();
                curnumber = value;
            }
            d[y][x] += rivit[y] + kolumnit[x] + 1;
            d[y][x] %= M;
            //System.out.println(rivit[y] + " " + kolumnit[x] + " " + d[y][x]);

            toedit.add(pair);
        }

        long sum = 0;
        StringBuilder builder = new StringBuilder();
        for (int y = 0; y < n; y++) {
            for (int x = 0; x < n; x++) {
                sum += d[y][x];
                //System.out.println(d[y][x]);
                //builder.append(d[y][x]).append(" ");
                sum %= M;
            }
            //builder.append("\n");
        }
        System.out.println(sum);
        //System.out.println(builder);
    }
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
3
1 1 1
1 1 1
1 1 1

correct output
9

user output
9

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
3
1 2 3
6 5 4
7 8 9

correct output
135

user output
135

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
3
7 8 1
4 5 4
3 9 6

correct output
57

user output
57

Test 4

Group: 2, 3

Verdict: ACCEPTED

input
100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
10000

user output
10000

Test 5

Group: 2, 3

Verdict: ACCEPTED

input
100
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
187458477

user output
187458477

Test 6

Group: 2, 3

Verdict: ACCEPTED

input
100
2995 8734 1018 2513 7971 5063 ...

correct output
964692694

user output
964692694

Test 7

Group: 3

Verdict: ACCEPTED

input
1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1000000

user output
1000000

Test 8

Group: 3

Verdict:

input
1000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
229147081

user output
(empty)

Test 9

Group: 3

Verdict:

input
1000
520283 805991 492643 75254 527...

correct output
951147313

user output
(empty)