Code Submission Evaluation System Login

Datatähti 2016 alku

Start:2015-09-28 00:00:00
End:2015-10-12 00:00:00
 

Tasks | Scoreboard | Statistics


CSES - Datatähti 2016 alku - Results
History
2015-10-11 09:52:57100
2015-10-11 00:22:5814
2015-10-10 23:54:2114
2015-10-10 23:11:5114
2015-10-10 23:11:200
2015-10-10 23:10:5214
2015-10-10 23:10:3114
2015-10-10 23:10:0514
2015-10-10 23:09:2347
2015-10-10 23:08:5947
2015-10-10 23:08:3947
2015-10-10 23:08:1147
2015-10-10 23:07:4747
2015-10-10 23:03:490
2015-10-10 22:24:240
2015-10-10 22:10:040
2015-10-10 21:54:490
2015-10-10 21:52:230
2015-10-10 21:38:360
2015-10-10 19:55:380
2015-10-10 19:52:070
2015-10-10 19:51:330
2015-10-10 19:51:010
2015-10-10 19:50:350
2015-10-10 19:48:300
2015-10-10 19:43:040
2015-10-10 19:42:410
2015-10-10 19:42:210
2015-10-10 19:41:590
2015-10-10 19:41:370
2015-10-10 19:40:1114
2015-10-10 19:39:410
2015-10-10 19:38:310
2015-10-10 19:36:440
2015-10-10 19:32:3547
2015-10-10 19:32:1247
2015-10-10 19:31:4847
2015-10-10 19:31:2547
2015-10-10 19:30:5047
2015-10-10 19:29:4147
2015-10-10 18:16:2047
2015-10-10 18:14:0247
2015-10-10 14:49:0247
2015-10-10 14:30:190
2015-10-10 13:56:3147
2015-10-10 13:55:400
2015-10-10 13:54:220
2015-10-10 12:22:1247
2015-10-10 12:21:1247
2015-10-10 12:20:2947
2015-10-10 11:54:4647
2015-10-10 11:29:4533
2015-10-10 11:29:29
2015-10-09 09:21:4447
2015-10-09 09:20:310
2015-10-09 08:59:0047
2015-10-07 15:00:0114
2015-10-07 14:49:0614
2015-10-07 14:28:020
2015-10-07 14:25:240
2015-10-07 14:15:570
2015-10-07 14:15:16
Task:Tontti
Sender:testUser
Submission time:2015-10-11 09:52:57
Language:Java
Status:READY
Score:100

Feedback

groupverdictscore
#1ACCEPTED14
#2ACCEPTED33
#3ACCEPTED53

Test results

testverdicttime (s)group
#1ACCEPTED0.18 / 1.001details
#2ACCEPTED0.17 / 1.001details
#3ACCEPTED0.17 / 1.001details
#4ACCEPTED0.19 / 1.001details
#5ACCEPTED0.19 / 1.001details
#6ACCEPTED0.41 / 1.002details
#7ACCEPTED0.35 / 1.002details
#8ACCEPTED0.30 / 1.002details
#9ACCEPTED0.31 / 1.002details
#10ACCEPTED0.30 / 1.002details
#11ACCEPTED0.92 / 1.003details
#12ACCEPTED0.99 / 1.003details
#13ACCEPTED0.76 / 1.003details
#14ACCEPTED0.79 / 1.003details
#15ACCEPTED0.79 / 1.003details

Code

import java.util.Random;

/**
 * Created by Frans on 5.10.2015.
 */
public class Tontti{

    static int height;
    static int width;
    static int[][] kenttaSumma;
    //static int[][] kentta;
    static int wantedTrees;

    static int lastSize;
    static double multiplier;

    static long runAmountB;
    static long runAmountBU;
    static long runAmountBD;
    static long runAmountL;
    static long runAmountL2;

    /*static final int testInt = 100000*1;
    static int seed = 1606; //(int) (Math.random()*10000);
    static int loop = 0;

    static int did = 0;
    */

    public static void main(String[] args){

        IO io = new IO();

        /*
        int foundArea = 0;
        int minSize = 0;
        multiplier = 0;
        int trees = 0;
        */

        /*
        long aika = System.nanoTime();

        Random generator = new Random(seed);

        //while(did==0) {
            //todo
            loop ++;

            int futureWidth = 2000;
            int futureHeight = 2000;
            int futureWantedTrees = (int) (1+ 1 * Math.pow(10, 1));
            height = futureHeight;
            width = futureWidth;
            wantedTrees = futureWantedTrees;

            kenttaSumma = new int[width + 1][height + 1];
            kentta = new int[width + 1][height + 1];


            String[] lines = new String[height + 1];
            for (int y = 1; y <= height; y++) {
                lines[y] = "";
                for (int x2 = 1; x2 <= width; x2++) {
                    if (generator.nextDouble() > 0.2) {
                        lines[y] = lines[y] + ".";
                    } else {
                        lines[y] = lines[y] + "*";
                    }
                }
            }
            kenttaSumma = new int[width + 1][height + 1];

        */
            int foundArea = 0;
            int minSize = (int) (Math.sqrt(wantedTrees) + 0.99);
            multiplier = 0;
            int trees = 0;


            height = io.nextInt();
            width = io.nextInt();
            wantedTrees = io.nextInt();
            kenttaSumma = new int[width+1][height+1];



            //calculate trees and save it in to array and summed area table
            for (int y = 1; y <= height; y++) {
                final char[] line = io.next().toCharArray();
                //final char[] line = lines[y].toCharArray();

                int sumRow = 0;
                for (int x = 1; x <= width; x++) {
                    if (line[x - 1] == '*') {
                        sumRow++;
                        trees++;
                        //kentta[x][y]=1;
                    }
                    kenttaSumma[x][y] = sumRow + kenttaSumma[x][y - 1];
                    int maxSize = min(x, y);

                    if (maxSize >= minSize) {
                        foundArea += countAreasS(maxSize, minSize, x, y);
                    }
                }

                lastSize = minSize;
            }

        //}

        io.println(foundArea);

        /*
        aika = (System.nanoTime()-aika)/1000000;
        io.println("---");
        io.println("Time: " + aika);
        io.println("Loops Binary: " + runAmountB/1000000.0);
        io.println("   -high: " + runAmountBU/1000000.0);
        io.println("   -low: " + runAmountBD/1000000.0);
        io.println("Loops Linear: " + runAmountL/1000000.0);
        io.println("Loops Linear: " + runAmountL2/1000000.0);
        io.println(multiplier);
        io.println(did);
        io.println("Loop: " + loop);
        */

        io.close();
    }

    //rekursiivinen binaarihaku
    // x2 = x -1
    // y2 = y -1
    private static int countAreasB(int maxSize,int minSize, int x, int y, int prevSize, double weight){
        int areasFound = 0;
        int tSize = (int) (((maxSize*(1.0+weight) + minSize*(1.0-weight))/2.0));

        if (tSize == prevSize){
            tSize = (int) (((maxSize + minSize)/2.0));
        }

        //lopetaan kun sama on jo katsottu
        if (prevSize != tSize){
            prevSize = tSize;

            int sum = kenttaSumma[x][y]+kenttaSumma[x-tSize][y-tSize]-kenttaSumma[x][y-tSize]-kenttaSumma[x-tSize][y];

            if(sum > wantedTrees){
                //tSize = (int) (Math.sqrt(tSize*tSize-(sum-wantedTrees))+0.999); //pitkalle johdettu matemaattinen optimointi
                multiplier = max(multiplier - 0.1, -0.95);
                areasFound += countAreasB(tSize, minSize, x, y, prevSize,multiplier);
            }else if (sum < wantedTrees){
                tSize = (maxSize - tSize == 1)?maxSize+1:tSize; //estetaan pyoristysvirhe
                multiplier = min(multiplier+0.1,0.95);
                areasFound += countAreasB(maxSize, tSize, x, y, prevSize,multiplier);
            }else {
                //molemmat suunnat ovat mahdollisia --> kokeillaan kaikki lahella olevat
                areasFound ++;
                /*// if (wantedTrees > testInt) {
                    int test1 = 0;
                    test1 += countAreasL(tSize + 1, maxSize, x, y, 1);
                    test1 += countAreasL(tSize - 1, minSize, x, y, -1);
                    areasFound += countAreasL(tSize + 1, maxSize, x, y, 1);
                    areasFound += countAreasL(tSize - 1, minSize, x, y, -1);
                }else{
                    int test2 = 0;
                    test2 += findSize(tSize + 1, maxSize, x, y, 1);
                    test2 += findSize(tSize - 1, minSize, x, y, -1);

                }*/
                areasFound += findSize(tSize +1, maxSize, x, y, 1);
                areasFound += findSize(tSize -1, minSize, x, y, -1);
                /*
                if (test1 != test2){
                    System.out.println("Seed: " + seed);
                    did = 1;
                }
                */
                lastSize = prevSize;
            }
        }
        
        return areasFound;
    }

    //rekursiivinen binaarihauen alku
    // x2 = x -1
    // y2 = y -1
    private static int countAreasS(int maxSize,int minSize, int x, int y){
        int areasFound = 0;
        int tSize = lastSize;
        //int tSize = min(max(lastSize,minSize),maxSize);
        int prevSize = tSize;

        runAmountB ++;
        int sum = kenttaSumma[x][y]+kenttaSumma[x-tSize][y-tSize]-kenttaSumma[x][y-tSize]-kenttaSumma[x-tSize][y];

        if(sum > wantedTrees){
            runAmountBU ++;
            //tSize = (int) (Math.sqrt(tSize*tSize-(sum-wantedTrees))+0.999); //pitkalle johdettu matemaattinen optimointi

            areasFound += countAreasB(tSize, minSize, x, y, prevSize,0.9);
        }else if (sum < wantedTrees){
            runAmountBD ++;
            tSize = (maxSize - tSize == 1)?maxSize+1:tSize; //estetaan pyoristysvirhe
            areasFound += countAreasB(maxSize, tSize, x, y, prevSize,-0.9);
        }else {
            areasFound ++;
                /*// if (wantedTrees > testInt) {
                    int test1 = 0;
                    test1 += countAreasL(tSize + 1, maxSize, x, y, 1);
                    test1 += countAreasL(tSize - 1, minSize, x, y, -1);
                    areasFound += countAreasL(tSize + 1, maxSize, x, y, 1);
                    areasFound += countAreasL(tSize - 1, minSize, x, y, -1);
                }else{
                    int test2 = 0;
                    test2 += findSize(tSize + 1, maxSize, x, y, 1);
                    test2 += findSize(tSize - 1, minSize, x, y, -1);

                }*/
            areasFound += findSize(tSize +1, maxSize, x, y, 1);
            areasFound += findSize(tSize -1, minSize, x, y, -1);
                /*
                if (test1 != test2){
                    System.out.println("Seed: " + seed);
                    did = 1;
                }
                */
        }

        return areasFound;
    }


    //suoraviivainen haku, yksitellen
    // x2 = x-1
    // y2 = y-1
    private static int countAreasL(int startSize,int endSize, int x, int y, int direction){
        int areasFound = 0;

        runAmountL ++;
        for (int tSize=startSize; direction*tSize<=endSize*direction; tSize=tSize+direction){
            runAmountL2 ++;
            int sum = kenttaSumma[x][y]+kenttaSumma[x-tSize][y-tSize]-kenttaSumma[x][y-tSize]-kenttaSumma[x-tSize][y];
            if (sum == wantedTrees){
                areasFound ++;
                lastSize = tSize;
            }else{
                break;
            }

        }

        return areasFound;
    }

    //rekursiivinen binaarihaku tyhjille kohdille
    private static int findSize(int startSize,int endSize, int x, int y,int direction){

        int foundArea = 0;
        if (direction*(endSize-startSize) <=4) {
            foundArea = countAreasL(startSize,endSize,x,y,direction);
        }else{
            int tSize = (int) ((startSize + endSize) / 2.0);
            int sum = kenttaSumma[x][y] + kenttaSumma[x - tSize][y - tSize] - kenttaSumma[x][y - tSize] - kenttaSumma[x - tSize][y];
            if (sum*direction < wantedTrees*direction) {
                foundArea = findSize(tSize, endSize, x, y,direction);
            }else if (sum*direction > wantedTrees*direction) {
                foundArea = findSize(startSize, tSize, x, y,direction);
            }else{
                foundArea = (tSize - startSize)*direction;
                foundArea += findSize(tSize, endSize, x, y,direction);
            }
        }
        return foundArea;
    }

    //just for lulz
    private static int max(final int a, final int b){
        return (a>b)?a:b;
    }
    private static int min(final int a, final int b){
        return (a<b)?a:b;
    }
    private static double min(final double a, final double b){
        return (a<b)?a:b;
    }
    private static double max(final double a, final double b){
        return (a>b)?a:b;
    }


}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
10 10 1
......*...
.......*..
*..*....*.
*....*....
...
view   save

correct output
94

view   save

user output
94

view   save

Test 2

Group: 1

Verdict: ACCEPTED

input
10 10 5
**********
**********
**********
**********
...
view   save

correct output
0

view   save

user output
0

view   save

Test 3

Group: 1

Verdict: ACCEPTED

input
10 10 10
**...*...*
*..*.**.*.
...**.*..*
*...**.*..
...
view   save

correct output
4

view   save

user output
4

view   save

Test 4

Group: 1

Verdict: ACCEPTED

input
10 10 5
****......
*.*.**..**
....*.*..*
...*.***..
...
view   save

correct output
16

view   save

user output
16

view   save

Test 5

Group: 1

Verdict: ACCEPTED

input
10 10 2
**.***..*.
...*.*....
.***.*...*
***.***..*
...
view   save

correct output
30

view   save

user output
30

view   save

Test 6

Group: 2

Verdict: ACCEPTED

input
500 500 1
.................................
view   save

correct output
9552040

view   save

user output
9552040

view   save

Test 7

Group: 2

Verdict: ACCEPTED

input
500 500 5
.................................
view   save

correct output
1536063

view   save

user output
1536063

view   save

Test 8

Group: 2

Verdict: ACCEPTED

input
500 500 25000
**...*...**..*.*..*.**.*..*.*....
view   save

correct output
288

view   save

user output
288

view   save

Test 9

Group: 2

Verdict: ACCEPTED

input
500 500 12500
**.**.*..*...*.**...*.***........
view   save

correct output
786

view   save

user output
786

view   save

Test 10

Group: 2

Verdict: ACCEPTED

input
500 500 5000
.*.*.**..*.*.**.**..*..**...*....
view   save

correct output
1763

view   save

user output
1763

view   save

Test 11

Group: 3

Verdict: ACCEPTED

input
2000 2000 1
.................................
view   save

correct output
489611392

view   save

user output
489611392

view   save

Test 12

Group: 3

Verdict: ACCEPTED

input
2000 2000 5
.................................
view   save

correct output
120725884

view   save

user output
120725884

view   save

Test 13

Group: 3

Verdict: ACCEPTED

input
2000 2000 400000
..*..**.**.**.*.***...**.*..**...
view   save

correct output
1849

view   save

user output
1849

view   save

Test 14

Group: 3

Verdict: ACCEPTED

input
2000 2000 200000
***.*....*.*..*....**..*..*.*....
view   save

correct output
2665

view   save

user output
2665

view   save

Test 15

Group: 3

Verdict: ACCEPTED

input
2000 2000 80000
**.**...*.***.**....**.*....*....
view   save

correct output
5587

view   save

user output
5587

view   save