| Task: | Osajono |
| Sender: | testUser |
| Submission time: | 2015-10-10 19:35:55 +0300 |
| Language: | Java |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | RUNTIME ERROR | 0 |
| #2 | RUNTIME ERROR | 0 |
| #3 | RUNTIME ERROR | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | RUNTIME ERROR | 0.17 s | 1 | details |
| #2 | RUNTIME ERROR | 0.17 s | 1 | details |
| #3 | RUNTIME ERROR | 0.17 s | 1 | details |
| #4 | RUNTIME ERROR | 0.18 s | 1 | details |
| #5 | RUNTIME ERROR | 0.18 s | 1 | details |
| #6 | RUNTIME ERROR | 0.17 s | 2 | details |
| #7 | RUNTIME ERROR | 0.17 s | 2 | details |
| #8 | RUNTIME ERROR | 0.18 s | 2 | details |
| #9 | RUNTIME ERROR | 0.18 s | 2 | details |
| #10 | RUNTIME ERROR | 0.17 s | 2 | details |
| #11 | RUNTIME ERROR | 0.17 s | 3 | details |
| #12 | RUNTIME ERROR | 0.18 s | 3 | details |
| #13 | RUNTIME ERROR | 0.17 s | 3 | details |
| #14 | RUNTIME ERROR | 0.17 s | 3 | details |
| #15 | RUNTIME ERROR | 0.18 s | 3 | details |
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 wantedTrees;
static int lastSize;
static double multiplier;
static long runAmountB;
static long runAmountBU;
static long runAmountBD;
static long runAmountL;
static long runAmountL2;
public static void main(String[] args){
/*//todo
int futureWidth = 2000;
int futureHeight = 2000;
int futureWantedTrees = (int) (2*Math.pow(10,2));
height = futureHeight;
width = futureWidth;
wantedTrees = futureWantedTrees;
kenttaSumma = new int[width+1][height+1];
Random generator = new Random(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.3){
lines[y] = lines[y] + ".";
}else {
lines[y] = lines[y] + "*";
}
}
}
kenttaSumma = new int[width+1][height+1];
*/
long aika = System.nanoTime();
IO io = new IO();
height = io.nextInt();
width = io.nextInt();
wantedTrees = io.nextInt();
kenttaSumma = new int[width+1][height+1];
int foundArea = 0;
int minSize = (int) (Math.sqrt(wantedTrees) + 0.99);
multiplier = 0;
mainLoop:
{
//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++;
}
kenttaSumma[x][y] = sumRow + kenttaSumma[x][y - 1];
if (System.nanoTime()-aika/Math.pow(10,9) > wantedTrees/100.0){
break;
}
int maxSize = min(x, y);
/*//todo remove
if (x == 1000 && y == 1000) {
//stop here
break mainLoop;
}*/
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.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;
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
multiplier = max(multiplier - 0.1, -0.95);
areasFound += countAreasB(tSize, minSize, x, y, prevSize,multiplier);
}else if (sum < wantedTrees){
runAmountBD ++;
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 ++;
areasFound += countAreasL(tSize+1, maxSize, x, y, 1);
areasFound += countAreasL(tSize-1, minSize, x, y, -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 {
//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, 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;
}
//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: RUNTIME ERROR
| input |
|---|
| BBBAABBBAAAABBAAAABAABAABBBBBB... |
| correct output |
|---|
| 2554 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(IO.java:111) at Tontti.main(Tontti.java:57)
Test 2
Group: 1
Verdict: RUNTIME ERROR
| input |
|---|
| GDFVYWQCZAFGICSXOSWBZMGPDBSSVL... |
| correct output |
|---|
| 299 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(IO.java:111) at Tontti.main(Tontti.java:57)
Test 3
Group: 1
Verdict: RUNTIME ERROR
| input |
|---|
| AAAAAAAAAAAAAAAAAAAAAAAAAZAAAA... |
| correct output |
|---|
| 4314 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(IO.java:111) at Tontti.main(Tontti.java:57)
Test 4
Group: 1
Verdict: RUNTIME ERROR
| input |
|---|
| AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
| correct output |
|---|
| 4231 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(IO.java:111) at Tontti.main(Tontti.java:57)
Test 5
Group: 1
Verdict: RUNTIME ERROR
| input |
|---|
| QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ... |
| correct output |
|---|
| 5050 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(IO.java:111) at Tontti.main(Tontti.java:57)
Test 6
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| BBABABBBABBAABBABBABAABAAABABA... |
| correct output |
|---|
| 6253029 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(IO.java:111) at Tontti.main(Tontti.java:57)
Test 7
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| RBKJMLDVQMKHYKCNDIVVKOMFUXTFMG... |
| correct output |
|---|
| 485173 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(IO.java:111) at Tontti.main(Tontti.java:57)
Test 8
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
| correct output |
|---|
| 12427725 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(IO.java:111) at Tontti.main(Tontti.java:57)
Test 9
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
| correct output |
|---|
| 12467549 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(IO.java:111) at Tontti.main(Tontti.java:57)
Test 10
Group: 2
Verdict: RUNTIME ERROR
| input |
|---|
| QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ... |
| correct output |
|---|
| 12502500 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(IO.java:111) at Tontti.main(Tontti.java:57)
Test 11
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| BAAAAABABBABAABAABABABBBABBAAB... |
| correct output |
|---|
| 2500051369 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(IO.java:111) at Tontti.main(Tontti.java:57)
Test 12
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| ABBURXDRVXAYBPXXOQZNYHLWGUEEWR... |
| correct output |
|---|
| 192407124 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(IO.java:111) at Tontti.main(Tontti.java:57)
Test 13
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
| correct output |
|---|
| 4998050400 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(IO.java:111) at Tontti.main(Tontti.java:57)
Test 14
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
| correct output |
|---|
| 4998850144 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(IO.java:111) at Tontti.main(Tontti.java:57)
Test 15
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ... |
| correct output |
|---|
| 5000050000 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(IO.java:111) at Tontti.main(Tontti.java:57)
