Submission #54366071


Source Code Expand

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        double N = Integer.parseInt(sc.next());
        ArrayList<String> baseShikaku = new ArrayList<>();
        double nagasa = Math.pow(3.0, N);
        double center = nagasa / 3;
        ArrayList<String> ans = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            ArrayList<String> centerShikaku = new ArrayList<>();
            // 四角を描画する処理
            if (i == 0) {
                baseShikaku.add("###");
                baseShikaku.add("#.#");
                baseShikaku.add("###");
            } else {
                int count = 0;
                for (String e : baseShikaku) {
                    baseShikaku.set(count, e + e + e);
                    String centerElement = ".";
                    centerShikaku.add(e + centerElement.repeat(e.length()) + e);
                    count++;
                }
                final ArrayList<String> temp = new ArrayList<>(baseShikaku);
                // こいつが真ん中なので特殊な処理をする

                baseShikaku.addAll(centerShikaku);
                baseShikaku.addAll(temp);
                // 真ん中を四角染める処理

            }
        }
        if (N == 0) {
            System.out.println("#");
        } else {
            for (String e : baseShikaku) {
                System.out.println(e);
            }
        }

    }

    public static boolean areCoprime(int a, int b) {
        return gcd(a, b) == 1;
    }

    public static int gcd(int a, int b) {
        while (b != 0) {
            int temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }

    public static int lcm(int a, int b) {
        return (a * (b / gcd(a, b)));
    }
}

class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;

        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    private void skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;

        }
    }

    public boolean hasNext() {
        skipUnprintable();
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}

Submission Info

Submission Time
Task C - Sierpinski carpet
User andrywawa
Language Java (OpenJDK 17)
Score 250
Code Size 4207 Byte
Status AC
Exec Time 112 ms
Memory 38300 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 250 / 250
Status
AC × 2
AC × 9
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt
Case Name Status Exec Time Memory
example_00.txt AC 40 ms 34096 KiB
example_01.txt AC 72 ms 37608 KiB
test_00.txt AC 85 ms 37956 KiB
test_01.txt AC 40 ms 34104 KiB
test_02.txt AC 75 ms 37444 KiB
test_03.txt AC 40 ms 33928 KiB
test_04.txt AC 73 ms 37412 KiB
test_05.txt AC 112 ms 38300 KiB
test_06.txt AC 72 ms 37344 KiB