結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー mikitmikit
提出日時 2021-02-20 00:13:55
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 8,713 bytes
コンパイル時間 2,628 ms
コンパイル使用メモリ 84,544 KB
実行使用メモリ 56,232 KB
最終ジャッジ日時 2023-10-17 02:12:35
合計ジャッジ時間 33,349 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
53,468 KB
testcase_01 AC 54 ms
53,476 KB
testcase_02 AC 56 ms
52,456 KB
testcase_03 AC 53 ms
51,428 KB
testcase_04 WA -
testcase_05 AC 54 ms
53,484 KB
testcase_06 AC 118 ms
55,984 KB
testcase_07 AC 107 ms
55,972 KB
testcase_08 AC 110 ms
56,132 KB
testcase_09 WA -
testcase_10 AC 104 ms
55,980 KB
testcase_11 AC 112 ms
56,140 KB
testcase_12 AC 104 ms
55,960 KB
testcase_13 AC 166 ms
55,956 KB
testcase_14 AC 119 ms
56,188 KB
testcase_15 AC 110 ms
55,932 KB
testcase_16 AC 152 ms
56,232 KB
testcase_17 AC 113 ms
55,980 KB
testcase_18 AC 117 ms
56,000 KB
testcase_19 AC 116 ms
56,020 KB
testcase_20 AC 55 ms
53,480 KB
testcase_21 AC 152 ms
56,036 KB
testcase_22 AC 113 ms
56,112 KB
testcase_23 AC 114 ms
55,904 KB
testcase_24 AC 176 ms
55,996 KB
testcase_25 AC 107 ms
56,092 KB
testcase_26 AC 166 ms
56,036 KB
testcase_27 WA -
testcase_28 AC 109 ms
55,916 KB
testcase_29 AC 113 ms
56,012 KB
testcase_30 AC 107 ms
54,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.CharBuffer;
import java.io.IOException;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.ByteBuffer;
import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import java.io.Writer;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner2 in = new LightScanner2(inputStream);
        LightWriter2 out = new LightWriter2(outputStream);
        No1398 solver = new No1398();
        solver.solve(1, in, out);
        out.close();
    }

    static class No1398 {
        public void solve(int testNumber, LightScanner2 in, LightWriter2 out) {
            int w = in.ints(), h = in.ints(), x = in.ints();
            if (x > 36) {
                out.ans(-1).ln();
                return;
            }

            int t = x;
            int[][] p = new int[3][3];
            p[0][0] = Math.min(t, 9);
            t -= p[0][0];
            p[0][1] = Math.min(t, 9);
            t -= p[0][1];
            p[1][0] = Math.min(t, 9);
            t -= p[1][0];
            p[1][1] = Math.min(t, 9);


            int[][] ans = new int[h + 2][w + 2];
            for (int py = 0; py < 3; py++) {
                trial:
                for (int px = 0; px < 3; px++) {
                    for (int i = 1; i <= h; i++) {
                        for (int j = 1; j <= w; j++) {
                            ans[i][j] = p[(i + py) % 3][(j + px) % 3];
                        }
                    }
                    for (int i = 1; i <= h; i++) {
                        for (int j = 1; j <= w; j++) {
                            int sum = 0;
                            for (int dy = -1; dy <= 1; dy++) {
                                for (int dx = -1; dx <= 1; dx++) {
                                    sum += ans[i + dy][j + dx];
                                }
                            }
                            if (sum != x) continue trial;
                        }
                    }
                    for (int i = 1; i <= h; i++) {
                        for (int j = 1; j <= w; j++) {
                            out.print((char) ('0' + ans[i][j]));
                        }
                        out.ln();
                    }
                    return;
                }
            }
            out.ans(-1).ln();
            return;
        }

    }

    static abstract class LightScannerAdapter implements AutoCloseable {
        public abstract void close();

    }

    static class LightScanner2 extends LightScannerAdapter {
        private static final int BUF_SIZE = 16 * 1024;
        private final InputStream stream;
        private final byte[] buf = new byte[BUF_SIZE];
        private int ptr;
        private int len;

        public LightScanner2(InputStream stream) {
            this.stream = stream;
        }

        private void reload() {
            try {
                ptr = 0;
                len = stream.read(buf);
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
        }

        private void load(int n) {
            if (ptr + n <= len) return;
            System.arraycopy(buf, ptr, buf, 0, len - ptr);
            len -= ptr;
            ptr = 0;
            try {
                int r = stream.read(buf, len, BUF_SIZE - len);
                if (r == -1) return;
                len += r;
                if (len != BUF_SIZE) buf[len] = '\n';
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
        }

        private void skip() {
            while (len != -1) {
                while (ptr < len && isTokenSeparator(buf[ptr])) ptr++;
                if (ptr < len) return;
                reload();
            }
            throw new NoSuchElementException("EOF");
        }

        public int ints() {
            skip();
            load(12);
            int b = buf[ptr++];
            boolean negate;
            if (b == '-') {
                negate = true;
                b = buf[ptr++];
            } else negate = false;
            int x = 0;
            for (; !isTokenSeparator(b); b = buf[ptr++]) {
                if ('0' <= b && b <= '9') x = x * 10 + b - '0';
                else throw new NumberFormatException("Unexpected character '" + ((char) b) + "'");
            }
            return negate ? -x : x;
        }

        public void close() {
            try {
                stream.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        private static boolean isTokenSeparator(int b) {
            return b < 33 || 126 < b;
        }

    }

    static class LightWriter2 implements AutoCloseable {
        private static final int BUF_SIZE = 16 * 1024;
        private final OutputStream out;
        private final byte[] buf = new byte[BUF_SIZE];
        private int ptr;
        private boolean autoflush = false;
        private boolean breaked = true;

        public LightWriter2(OutputStream out) {
            this.out = out;
        }

        public LightWriter2(Writer out) {
            this.out = new LightWriter2.WriterOutputStream(out);
        }

        private void allocate(int n) {
            if (ptr + n <= BUF_SIZE) return;
            try {
                out.write(buf, 0, ptr);
                ptr = 0;
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            if (BUF_SIZE < n) throw new IllegalArgumentException("Internal buffer exceeded");
        }

        public void close() {
            try {
                out.write(buf, 0, ptr);
                ptr = 0;
                out.flush();
                out.close();
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
        }

        public LightWriter2 print(char c) {
            allocate(1);
            buf[ptr++] = (byte) c;
            breaked = false;
            return this;
        }

        private static int countDigits(int l) {
            if (l >= 1000000000L) return 10;
            if (l >= 100000000L) return 9;
            if (l >= 10000000L) return 8;
            if (l >= 1000000L) return 7;
            if (l >= 100000L) return 6;
            if (l >= 10000L) return 5;
            if (l >= 1000L) return 4;
            if (l >= 100L) return 3;
            if (l >= 10L) return 2;
            return 1;
        }

        public LightWriter2 ans(int x) {
            allocate(12);
            if (!breaked) buf[ptr++] = ' ';
            breaked = false;

            if (x < 0) {
                buf[ptr++] = '-';
                x = -x;
            }
            int n = countDigits(x);
            for (int i = ptr + n - 1; ptr <= i; i--) {
                buf[i] = (byte) (x % 10 + '0');
                x /= 10;
            }
            ptr += n;

            return this;
        }

        public LightWriter2 ln() {
            allocate(1);
            buf[ptr++] = '\n';
            breaked = true;
            if (autoflush) {
                try {
                    out.flush();
                } catch (IOException ex) {
                    throw new UncheckedIOException(ex);
                }
            }
            return this;
        }

        private static class WriterOutputStream extends OutputStream {
            final Writer writer;
            final CharsetDecoder decoder;

            WriterOutputStream(Writer writer) {
                this.writer = writer;
                this.decoder = StandardCharsets.UTF_8.newDecoder();
            }

            public void write(int b) throws IOException {
                writer.write(b);
            }

            public void write(byte[] b) throws IOException {
                writer.write(decoder.decode(ByteBuffer.wrap(b)).array());
            }

            public void write(byte[] b, int off, int len) throws IOException {
                writer.write(decoder.decode(ByteBuffer.wrap(b, off, len)).array());
            }

            public void flush() throws IOException {
                writer.flush();
            }

            public void close() throws IOException {
                writer.close();
            }

        }

    }
}

0