CSES - Datatähti 2016 alku - Results
Submission details
Task:Tontti
Sender:testUser
Submission time:2015-10-10 13:55:40 +0300
Language:Java
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.17 s1details
#20.18 s1details
#30.17 s1details
#40.17 s1details
#50.17 s1details
#60.19 s2details
#70.17 s2details
#80.17 s2details
#90.17 s2details
#100.17 s2details
#110.17 s3details
#120.18 s3details
#130.17 s3details
#140.16 s3details
#150.17 s3details

Code

/**
* Created by Frans on 5.10.2015.
*/
public class Tontti{
static int height;
static int width;
static int[][] kenttaSumma;
static int wantedTrees;
static long runAmountB;
static long runAmountBU;
static long runAmountBD;
static long runAmountL;
public static void main(String[] args){
/*//todo
int futureWidth = 2000;
int futureHeight = 2000;
int futurewantedTrees = (int) (2*Math.pow(10,3));
height = futureHeight;
width = futureWidth;
wantedTrees = futurewantedTrees;
kenttaSumma = 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 (Math.random() > 0.3){
lines[y] = lines[y] + ".";
}else {
lines[y] = lines[y] + "*";
}
}
}
long aika = System.nanoTime();
kenttaSumma = new int[width+1][height+1];
*/
IO io = new IO();
height = io.nextInt();
width = io.nextInt();
wantedTrees = io.nextInt();
int foundArea = 0;
int minSize = (int) (Math.sqrt(wantedTrees) + 0.99);
//calculate trees and save it in to array and summed area table
for (int y = 1; y <= height; y++) {
String line = io.next();
//String line = lines[y];
int sumRow = 0;
for (int x = 1; x <= width; x++) {
if (line.charAt(x - 1) == '*') {
sumRow++;
}
kenttaSumma[x][y] = sumRow + kenttaSumma[x][y - 1];
int maxSize = min(x, y);
//todo remove
/*if (x==1999 && y==1999){
//stop here
break mainLoop;
}*/
if (maxSize >= minSize) {
foundArea += countAreasB(maxSize, minSize, x, y, 0);
}
}
}
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.close();
}
//rekursiivinen binaarihaku
// x2 = x -1
// y2 = y -1
private static int countAreasB(int maxSize,int minSize, int x, int y, int prevSize){
int areasFound = 0;
int tSize = (int) ((maxSize + minSize)/2.0 + 0.99);
//lopetaan kun sama on jo katsottu
if (prevSize != tSize){
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
tSize = (tSize - minSize <= 1)?minSize:tSize; //estetaan ikuinen pyoristyslooppi
areasFound += countAreasB(tSize, minSize, x, y, prevSize);
}else if (sum < wantedTrees){
runAmountBD ++;
areasFound += countAreasB(maxSize, tSize, x, y, prevSize);
}else {
//molemmat suunnat ovat mahdollisia --> kokeillaan kaikki lahella olevat
areasFound ++;
areasFound += countAreasL(tSize+1, maxSize, x, y, 1);
areasFound += countAreasL(tSize-1, minSize, x, y, -1);
}
}
return areasFound;
}
//suoraviivainen haku
// x2 = x-1
// y2 = y-1
private static int countAreasL(int startSize,int endSize, int x, int y, int direction){
int areasFound = 0;
for (int tSize=startSize; direction*tSize<=endSize*direction; tSize=tSize+direction){
runAmountL ++;
int sum = kenttaSumma[x][y]+kenttaSumma[x-tSize][y-tSize]-kenttaSumma[x][y-tSize]-kenttaSumma[x-tSize][y];
if (sum == wantedTrees){
areasFound ++;
}else{
break;
}
}
return areasFound;
}
//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;
}
}

Test details

Test 1

Group: 1

Verdict:

input
10 10 1
......*...
.......*..
*..*....*.
*....*....
...

correct output
94

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at Tontti.main(Tontti.java:65)

Test 2

Group: 1

Verdict:

input
10 10 5
**********
**********
**********
**********
...

correct output
0

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at Tontti.main(Tontti.java:65)

Test 3

Group: 1

Verdict:

input
10 10 10
**...*...*
*..*.**.*.
...**.*..*
*...**.*..
...

correct output
4

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at Tontti.main(Tontti.java:65)

Test 4

Group: 1

Verdict:

input
10 10 5
****......
*.*.**..**
....*.*..*
...*.***..
...

correct output
16

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at Tontti.main(Tontti.java:65)

Test 5

Group: 1

Verdict:

input
10 10 2
**.***..*.
...*.*....
.***.*...*
***.***..*
...

correct output
30

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at Tontti.main(Tontti.java:65)

Test 6

Group: 2

Verdict:

input
500 500 1
.................................

correct output
9552040

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at Tontti.main(Tontti.java:65)

Test 7

Group: 2

Verdict:

input
500 500 5
.................................

correct output
1536063

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at Tontti.main(Tontti.java:65)

Test 8

Group: 2

Verdict:

input
500 500 25000
**...*...**..*.*..*.**.*..*.*....

correct output
288

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at Tontti.main(Tontti.java:65)

Test 9

Group: 2

Verdict:

input
500 500 12500
**.**.*..*...*.**...*.***........

correct output
786

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at Tontti.main(Tontti.java:65)

Test 10

Group: 2

Verdict:

input
500 500 5000
.*.*.**..*.*.**.**..*..**...*....

correct output
1763

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at Tontti.main(Tontti.java:65)

Test 11

Group: 3

Verdict:

input
2000 2000 1
.................................

correct output
489611392

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at Tontti.main(Tontti.java:65)

Test 12

Group: 3

Verdict:

input
2000 2000 5
.................................

correct output
120725884

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at Tontti.main(Tontti.java:65)

Test 13

Group: 3

Verdict:

input
2000 2000 400000
..*..**.**.**.*.***...**.*..**...

correct output
1849

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at Tontti.main(Tontti.java:65)

Test 14

Group: 3

Verdict:

input
2000 2000 200000
***.*....*.*..*....**..*..*.*....

correct output
2665

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at Tontti.main(Tontti.java:65)

Test 15

Group: 3

Verdict:

input
2000 2000 80000
**.**...*.***.**....**.*....*....

correct output
5587

user output
(empty)

Error:
Exception in thread "main" java.lang.NullPointerException
	at Tontti.main(Tontti.java:65)