CSES - Datatähti 2018 alku - Results
Submission details
Task:Fraktaali
Sender:RoniTuohino
Submission time:2017-10-04 15:42:30 +0300
Language:Java
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED10
#2ACCEPTED10
#3ACCEPTED10
#4ACCEPTED10
#5ACCEPTED10
#6ACCEPTED10
#7ACCEPTED10
#8ACCEPTED10
#9ACCEPTED10
#10ACCEPTED10
Test results
testverdicttimegroup
#1ACCEPTED0.14 s1details
#2ACCEPTED0.16 s2details
#3ACCEPTED0.16 s3details
#4ACCEPTED0.16 s4details
#5ACCEPTED0.18 s5details
#6ACCEPTED0.19 s6details
#7ACCEPTED0.21 s7details
#8ACCEPTED0.24 s8details
#9ACCEPTED0.35 s9details
#10ACCEPTED0.53 s10details

Code

import java.util.*;
public class Main {
    public static void main(String[] args) {
	    Scanner s = new Scanner(System.in);
	    int f = s.nextInt();
	    int size = (int)CalculateSize(f);

		char[][]startFrac = new char[size][size];

		for (int x = 0; x < startFrac.length; x++){	//Turn all spaces black '#'
			for (int y = 0; y < startFrac.length; y++){
				startFrac[x][y] = '#';
			}
		}

		startFrac = BuildFractal(startFrac, size, f);
		PrintFractal(startFrac);
    }

    public  static  double CalculateSize(double x){		//Calculate the size for the fractal
    	if(x == 1){
    		x = 1;
		} else if(x == 2){
    		x = 2;
		} else if(x == 3){
			x = 4;
		} else if(x == 4){
			x = 8;
		} else if(x >= 5){
			x = Math.pow(2, x-1);
		}
    	return  x;
	}

	public static char[][] BuildFractal(char[][] frac, int size, int f){ //Build the final fractal
    	char[][] finalFrac;

    	finalFrac = frac;

		if(f == 1){
			return finalFrac;
		}

		finalFrac[1][1] = '.';	//First white piece on the corner
		if(f == 2){
			return finalFrac;
		}

		for(int i = 2; i < f; i++){	//Do this loop until fractal is complete
			//Insert all the corners of the fractal
			finalFrac = SetTheCorners(finalFrac, (int)CalculateSize(i+1) ,(int)CalculateSize(i));

		}

		return finalFrac;
	}

	public  static  char[][] SetTheCorners(char[][] frac, int size, int pos){	//Set the on the fractal
		char[][] finalFrac = frac;
		char[][] copy = new char[pos][pos];
		//System.out.println(pos);
		for(int x = 0; x < pos; x++){	//Copy is now the corner to set
			for(int y = 0; y < pos; y++){
				copy[x][y] = finalFrac[x][y];
			}
		}

		for(int x = 0; x <= pos - 1; x++){	//Set the first corner on the top right
			for(int y = pos; y <= size - 1; y++){
				if(copy[x][y - pos] == '.'){
					finalFrac[x][y] = '.';
				}
			}
		}

		for(int x = pos; x <= size - 1; x++){	//Set the second corner on the bottom left
			for(int y = 0; y <= pos - 1; y++){
				if(copy[x - pos][y] == '.'){
					finalFrac[x][y] = '.';
				}
			}
		}

		for(int x = pos; x <= size - 1; x++){	//Scans the bottom right negative
			for(int y = pos; y <= size - 1; y++){
				//finalFrac[x][y] = '.';
				if(copy[x - pos][y - pos] == '#'){
					finalFrac[x][y] = '.';
				}
				else if(copy[x - pos][y - pos] == '.'){
					finalFrac[x][y] = '#';
				}
			}
		}
		return finalFrac;
	}

    public static void PrintFractal(char[][] frac){	//Print the fractal
		for (int x = 0; x < frac.length; x++){
			System.out.println("");
			for(int y=0; y < frac.length; y++){
				System.out.print(frac[x][y]);
			}
		}
	}
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
1

correct output
#

user output

#

Test 2

Group: 2

Verdict: ACCEPTED

input
2

correct output
##
#.

user output

##
#.

Test 3

Group: 3

Verdict: ACCEPTED

input
3

correct output
####
#.#.
##..
#..#

user output

####
#.#.
##..
#..#

Test 4

Group: 4

Verdict: ACCEPTED

input
4

correct output
########
#.#.#.#.
##..##..
#..##..#
####....
...

user output

########
#.#.#.#.
##..##..
#..##..#
...

Test 5

Group: 5

Verdict: ACCEPTED

input
5

correct output
################
#.#.#.#.#.#.#.#.
##..##..##..##..
#..##..##..##..#
####....####....
...

user output

################
#.#.#.#.#.#.#.#.
##..##..##..##..
#..##..##..##..#
...

Test 6

Group: 6

Verdict: ACCEPTED

input
6

correct output
##############################...

user output

##############################...

Test 7

Group: 7

Verdict: ACCEPTED

input
7

correct output
##############################...

user output

##############################...

Test 8

Group: 8

Verdict: ACCEPTED

input
8

correct output
##############################...

user output

##############################...

Test 9

Group: 9

Verdict: ACCEPTED

input
9

correct output
##############################...

user output

##############################...

Test 10

Group: 10

Verdict: ACCEPTED

input
10

correct output
##############################...

user output

##############################...