CSES - Datatähti 2024 alku - Results
Submission details
Task:Säähavainnot
Sender:andreibe
Submission time:2023-11-12 13:38:52 +0200
Language:Java
Status:READY
Result:56
Feedback
groupverdictscore
#1ACCEPTED56.38
Test results
testverdicttimescore
#1ACCEPTED0.31 s7.38details
#2ACCEPTED0.32 s7.25details
#3ACCEPTED0.31 s7.5details
#4ACCEPTED0.33 s6.75details
#5ACCEPTED0.32 s7.13details
#6ACCEPTED0.32 s6.75details
#7ACCEPTED0.32 s6.75details
#8ACCEPTED0.32 s6.88details

Code

import java.util.*;
import java.util.stream.Collectors;

public class Main {
    //@SuppressWarnings({"SpellCheckingInspection", "ForLoopReplaceableByForEach"})
    static class Paiva {
        double[] oikea = new double[12];
        double[] edellinenPaiva = new double[24];

        double[] arvaus = new double[12];

        double keskiarvo = 1;

        public Paiva() {
            Arrays.fill(arvaus, Double.NaN);
        }

        static class P {
            public P(int a, int b) {
                this.a = a;
                this.b = b;
            }

            int a, b;
        }

        boolean isTasainen(double maxEro) {
            double summa = 0;
            double maara = 0;
            for (int i = 0; i < edellinenPaiva.length; i++) {
                summa += edellinenPaiva[i];
                maara++;
            }
            double keskiarvo = summa / maara;
            this.keskiarvo = keskiarvo;
            for (int i = 0; i < edellinenPaiva.length; i++) {
                if (Math.abs(edellinenPaiva[i] - keskiarvo) > maxEro) {
                    return false;
                }
            }
            return true;
        }

        P pisteet() {
            int a = 0;
            int b = 0;
            for (int i = 0; i < arvaus.length; i++) {
                double arv = arvaus[i];
                if (Double.isNaN(arv)) continue; //?
                double oik = oikea[i];
                if (Math.abs(arv - oik) < 0.75) a++;
                else if (Math.abs(arv - oik) >= 2.05) b++;
            }
            return new P(a, b);
        }
    }
    double addIf(double prev, double now, double value) {
        if ( prev - now > 0.75) value -= Math.abs(prev - now) / 4;
        else if (prev - now < -0.75) value += Math.abs(prev - now) / 4;
        return value;
    }
    //@SuppressWarnings("UnusedReturnValue")
    int main() {
        Scanner scanner = new Scanner(Main.class.getResourceAsStream("/input.txt"));
        int n = Integer.parseInt(scanner.nextLine());
        ArrayList<Paiva> paivat = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            String[] line = scanner.nextLine().split(" ");
            Paiva paiva = new Paiva();
            for (int j = 0; j < line.length; j++) {
                double d = Double.parseDouble(line[j]);
                if (j < 24) {
                    paiva.edellinenPaiva[j] = d;
                } else {
                    paiva.oikea[j - 24] = d;
                }
            }
            paivat.add(paiva);
        }


        double maxEro = 1;
        List<Paiva> tasaiset = paivat.stream().filter(paiva -> paiva.isTasainen(maxEro)).collect(Collectors.toList());
        //System.out.println("Tasaisia " + tasaiset.size());


        for (Paiva paiva : paivat) {
            paiva.arvaus[0] = paiva.edellinenPaiva[23];
            //paiva.arvaus[1] = paiva.edellinenPaiva[23];
            //paiva.arvaus[2] = paiva.edellinenPaiva[23];
            //paiva.arvaus[3] = paiva.edellinenPaiva[23];
            paiva.arvaus[1] = addIf(paiva.edellinenPaiva[0], paiva.edellinenPaiva[1], paiva.edellinenPaiva[23]);
            paiva.arvaus[2] = addIf(paiva.edellinenPaiva[1], paiva.edellinenPaiva[2], paiva.edellinenPaiva[23]);
            paiva.arvaus[3] = addIf(paiva.edellinenPaiva[2], paiva.edellinenPaiva[3], paiva.edellinenPaiva[23]);
        }
        for (Paiva paiva : tasaiset) {
            for (int i = 4; i < 12; i++) {
                paiva.arvaus[i] = paiva.keskiarvo;
            }
            paiva.arvaus[10] = paiva.edellinenPaiva[0];
            paiva.arvaus[11] = paiva.edellinenPaiva[0];
        }

        int a = 0;
        int b = 0;

        int at = 0;
        int bt = 0;
        for (Paiva paiva : paivat) {
            Paiva.P pisteet = paiva.pisteet();
            a += pisteet.a;
            b += pisteet.b;

            if (paiva.isTasainen(maxEro)) {
                at += pisteet.a;
                bt += pisteet.b;
            }
        }
        //System.out.println(a + " " +  b + " " + n);
        //System.out.println(at + " " + bt);
        //System.out.println(a / (double)(b+a));


        StringBuilder builder = new StringBuilder();
        for (Paiva paiva : paivat) {
            for (double arvaus : paiva.arvaus) {
                if (Double.isNaN(arvaus)) builder.append("? ");
                else builder.append(arvaus).append(" ");
            }
            builder.append("\n");
        }
        System.out.println(builder);

        //System.out.println((int) (25 * (a - b) / (double) n));
        return 0;
    }

    public static void main(String[] args) {
        new Main().main();
    }
}

Test details

Test 1

Verdict: ACCEPTED

input
1000
-0.4 -0.1 -0.2 -0.3 -0.4 -0.5 ...

correct output
0.4 0.4 0.5 0.8 0.9 1.1 1.3 1....

user output
0.2 0.2 0.2 0.2 -0.50416666666...
Truncated

Test 2

Verdict: ACCEPTED

input
1000
2.9 2.9 2.9 2.1 2.6 2 2 2.2 2....

correct output
2.3 1.6 1.5 1.1 1 0.7 0.6 0.8 ...

user output
2.6 2.6 2.6 2.4000000000000004...
Truncated

Test 3

Verdict: ACCEPTED

input
1000
6.6 6 6.4 6 4.6 4.6 4.2 4.3 4....

correct output
10 10.9 10.3 10.1 9.1 7.3 5.7 ...

user output
10.1 10.1 10.1 10.1 ? ? ? ? ? ...
Truncated

Test 4

Verdict: ACCEPTED

input
1000
19.4 20.2 19.1 18.9 18.3 17.3 ...

correct output
18 18.2 17 17.5 17.2 16.2 12 8...

user output
17.2 17.4 16.925 17.2 ? ? ? ? ...
Truncated

Test 5

Verdict: ACCEPTED

input
1000
-5.7 -5.8 -5.8 -5.9 -7.1 -6.9 ...

correct output
-4.2 -4.1 -4 -3.8 -3.5 -3.2 -3...

user output
-4.5 -4.5 -4.5 -4.5 ? ? ? ? ? ...
Truncated

Test 6

Verdict: ACCEPTED

input
1000
14.8 14.8 15.4 12.9 11.8 9.7 9...

correct output
11.8 11 11.6 10.8 10.4 10.4 10...

user output
12.6 12.6 12.6 11.975 ? ? ? ? ...
Truncated

Test 7

Verdict: ACCEPTED

input
1000
0.7 1 2 1.4 0.6 -0.4 -0.9 -0.7...

correct output
-1.3 -0.5 -0.6 -1 -3.2 -7.2 -6...

user output
-1.8 -1.8 -1.55 -1.8 ? ? ? ? ?...
Truncated

Test 8

Verdict: ACCEPTED

input
1000
15.1 15.3 14.9 14.4 14.4 13.7 ...

correct output
15.6 15.9 16 15.2 14.6 14.4 13...

user output
15.0 15.0 15.0 15.0 ? ? ? ? ? ...
Truncated