CSES - Datatähti 2016 alku - Results
Submission details
Task:Tontti
Sender:kalh
Submission time:2015-10-01 14:19:48 +0300
Language:Java
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.17 s1details
#20.17 s1details
#30.18 s1details
#40.17 s1details
#50.18 s1details
#60.44 s2details
#70.37 s2details
#80.25 s2details
#90.23 s2details
#100.23 s2details
#11--3details
#12--3details
#13--3details
#140.76 s3details
#150.51 s3details

Code

import java.util.*;
import java.math.*;

public class Tehtava3 {
	
	public static class Puu {
		int x;
		int y;
		
		public Puu(int _x, int _y) {
			x = _x;
			y = _y;
		}
	}
	
	private static long kokaika;
	private static int[][] arvot;
	
	public static void laskeTavat(int korkeus, int leveys, String[] metsa, int puita) {
		
		
		long t = System.currentTimeMillis();
		int tulos = 0;
		
		
		int pieninKoko = (int)Math.ceil(Math.sqrt(puita));
		int maksimiKoko = Math.min(korkeus, leveys);
		ArrayList<Puu> puut = new ArrayList<Puu>();
		
		int viimearvovaaka = 0;
		int viimearvopysty = 0;

		
		//System.out.println("eka: " + (System.currentTimeMillis()-t));
		
		
		int maara = 0;
		
			
			for (int j = 0; j<=leveys-pieninKoko; j++) {
				
				for (int k = 0; k<=korkeus-pieninKoko; k++) {
					for (int i = pieninKoko; i<=maksimiKoko; i++) {
						if (k+i > korkeus || j+i > leveys)
							break;
						int maaraAlueella = puidenMaara(j, k, i);
						if (maaraAlueella == puita) {
						//System.out.println("levyeys: " + j +", korkeus: " + k + ", koko: " + i +", puita: " + maaraAlueella);
						maara++;
						}
						else if (maaraAlueella > puita) {
							break;
						}
					
					}
					
				}
				
			}
		
		//System.out.println("toka: " + (System.currentTimeMillis()-t));
		System.out.println(maara);
		
	}
	


	
	public static int puidenMaara(int alkux, int alkuy, int koko) {
		
		int arvo1 = 0;
		int arvo2 = 0;
		int arvo3 = 0;
		int arvo4 = 0;
		
		if (alkux != 0) {
			if (alkuy != 0) {
				arvo1 = arvot[alkux-1][alkuy-1];
				arvo2 = arvot[alkux+koko-1][alkuy-1];
			}
				arvo3 = arvot[alkux-1][alkuy];
		}
		
		else {
			if (alkuy != 0) {
				arvo2 = arvot[alkux+koko-1][alkuy-1];
			}
		}
		
		arvo4 = arvot[alkux+koko-1][alkuy+koko-1];
		
		
		return (arvo1+arvo4-arvo2-arvo3);
	}
	

	
	public static String[] luoSatunnainen(int leveys, int korkeus) {
		StringBuilder sb;
		String[] metsa = new String[korkeus];
		Random r = new Random();
		for (int i = 0; i<korkeus; i++) {
			sb = new StringBuilder();
			for (int j = 0; j<leveys; j++) {
				int a = r.nextInt(9);
				if (a <= 1)
					sb.append('*');
				else
					sb.append('.');
				
			}
			
			metsa[i] = sb.toString();
		}
		
		return metsa;
	}
	
	
	public static void tulostaMetsa(String[] metsa) {
	
		for (int i = 0; i<metsa.length; i++) {
			for (int j = 0; j<metsa[0].length(); j++) {
				System.out.print(metsa[i].charAt(j) + " ");
				
			}
			System.out.println();
			System.out.println("--------------------------------------");
		}
	}
	
	public static void luoArvoTaulukko(String[] metsa) {
		// metsa[0] = leveys
		//metsa = korkeus
		
		//arvot[0] = korkeus
		// arvot = leveys
		
		System.out.println(metsa[0].length());
		
		int summa1 = 0;
		for (int i = 0; i<metsa[0].length(); i++) {
			if (metsa[0].charAt(i) == '*') {
				summa1++;
			}
			arvot[i][0] = summa1;
		}
		
		int summa2 = 0;
		for (int y = 1; y<metsa.length; y++) {
			summa1 = 0;
			summa2 = 0;
			
			for (int x = 0; x<metsa[0].length(); x++) {
				
				if (metsa[y].charAt(x) == '*')
					summa2++;
				
				summa1 = arvot[x][y-1];
						
				
				arvot[x][y] = (summa1+summa2);
			}
		}
	}
	
	public static void tulostaArvoTaulukko() {
		for (int i = 0; i<arvot[0].length; i++) {
			for (int j = 0; j<arvot.length; j++) {
				System.out.print(arvot[j][i] + " | ");
			}
			System.out.println("--------------");
		}
	}

	public static void main(String[] args) {
		
		
		IO io = new IO();
		int korkeus = io.nextInt();
		int leveys = io.nextInt();
		int puita = io.nextInt();
		

		
		//int korkeus = 200;
		//int leveys = 200;
		//int puita = 20;
		
		
		String[] metsa = new String[korkeus];
		
		//kokaika = 0;
		
		for (int i = 0; i<korkeus; i++) {
			metsa[i] = io.next();
		}
		
		arvot = new int[leveys][korkeus];
		

		//metsa[0] = "..**..";
		//metsa[1] = "**....";
		//metsa[2] = "*...*.";
		//metsa[3] = "..*...";
		
		
		
		
		//metsa = luoSatunnainen(leveys, korkeus);
		//tulostaMetsa(metsa);

	//
		luoArvoTaulukko(metsa);
		
		
		laskeTavat(korkeus, leveys, metsa, puita);

	}
	

}

Test details

Test 1

Group: 1

Verdict:

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

correct output
94

user output
10
72

Test 2

Group: 1

Verdict:

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

correct output
0

user output
10
0

Test 3

Group: 1

Verdict:

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

correct output
4

user output
10
4

Test 4

Group: 1

Verdict:

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

correct output
16

user output
10
8

Test 5

Group: 1

Verdict:

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

correct output
30

user output
10
12

Test 6

Group: 2

Verdict:

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

correct output
9552040

user output
500
11363077

Test 7

Group: 2

Verdict:

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

correct output
1536063

user output
500
1634147

Test 8

Group: 2

Verdict:

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

correct output
288

user output
500
245

Test 9

Group: 2

Verdict:

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

correct output
786

user output
500
231

Test 10

Group: 2

Verdict:

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

correct output
1763

user output
500
304

Test 11

Group: 3

Verdict:

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

correct output
489611392

user output
(empty)

Test 12

Group: 3

Verdict:

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

correct output
120725884

user output
(empty)

Test 13

Group: 3

Verdict:

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

correct output
1849

user output
(empty)

Test 14

Group: 3

Verdict:

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

correct output
2665

user output
2000
1033

Test 15

Group: 3

Verdict:

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

correct output
5587

user output
2000
1150