Submission #1131260


Source Code Expand

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Egor Kulikov (egor@egork.net)
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            char[][] map = IOUtils.readTable(in, n, n);
            int fill = n + 1;
            for (int i = 0; i < n; i++) {
                boolean has = false;
                for (int j = 0; j < n; j++) {
                    if (map[j][i] == '#') {
                        has = true;
                        break;
                    }
                }
                if (has) {
                    int current = 0;
                    for (int j = 0; j < n; j++) {
                        if (map[i][j] == '.') {
                            current++;
                        }
                    }
                    fill = Math.min(fill, current);
                }
            }
            if (fill == n + 1) {
                out.printLine(-1);
                return;
            }
            int answer = fill;
            for (int i = 0; i < n; i++) {
                boolean good = true;
                for (int j = 0; j < n; j++) {
                    if (map[j][i] == '.') {
                        good = false;
                        break;
                    }
                }
                if (!good) {
                    answer++;
                }
            }
            out.printLine(answer);
        }

    }

    static class IOUtils {
        public static char[] readCharArray(InputReader in, int size) {
            char[] array = new char[size];
            for (int i = 0; i < size; i++) {
                array[i] = in.readCharacter();
            }
            return array;
        }

        public static char[][] readTable(InputReader in, int rowCount, int columnCount) {
            char[][] table = new char[rowCount][];
            for (int i = 0; i < rowCount; i++) {
                table[i] = readCharArray(in, columnCount);
            }
            return table;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

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

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public char readCharacter() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            return (char) c;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

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

        public void printLine(int i) {
            writer.println(i);
        }

    }
}

Submission Info

Submission Time
Task B - Row to Column
User Egor
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 5547 Byte
Status WA
Exec Time 158 ms
Memory 23252 KB

Judge Result

Set Name Sample Subtask All
Score / Max Score 0 / 0 0 / 300 0 / 1000
Status
AC × 5
AC × 19
WA × 1
AC × 40
WA × 3
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt
Subtask 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 2_00.txt, 2_01.txt, 2_02.txt, 2_03.txt, 2_04.txt, 2_05.txt, 2_06.txt, 2_07.txt, 2_08.txt, 2_09.txt, 2_10.txt, 2_11.txt, 2_12.txt, 2_13.txt, 2_14.txt, 2_15.txt, 2_16.txt, 2_17.txt, 2_18.txt, 2_19.txt, 2_20.txt, 2_21.txt, 2_22.txt
Case Name Status Exec Time Memory
0_00.txt AC 69 ms 19540 KB
0_01.txt AC 69 ms 18644 KB
0_02.txt AC 79 ms 19280 KB
0_03.txt AC 69 ms 18772 KB
0_04.txt AC 69 ms 21460 KB
1_00.txt AC 68 ms 17876 KB
1_01.txt AC 67 ms 20308 KB
1_02.txt AC 69 ms 18260 KB
1_03.txt AC 70 ms 23252 KB
1_04.txt AC 69 ms 19412 KB
1_05.txt AC 70 ms 19284 KB
1_06.txt WA 70 ms 18516 KB
1_07.txt AC 69 ms 21460 KB
1_08.txt AC 66 ms 17620 KB
1_09.txt AC 69 ms 18516 KB
1_10.txt AC 68 ms 19284 KB
1_11.txt AC 69 ms 20436 KB
1_12.txt AC 69 ms 19156 KB
1_13.txt AC 69 ms 19412 KB
1_14.txt AC 68 ms 20948 KB
2_00.txt AC 92 ms 20692 KB
2_01.txt AC 101 ms 20052 KB
2_02.txt AC 101 ms 22608 KB
2_03.txt AC 99 ms 21332 KB
2_04.txt AC 99 ms 21844 KB
2_05.txt AC 101 ms 22484 KB
2_06.txt WA 101 ms 21844 KB
2_07.txt AC 95 ms 20052 KB
2_08.txt AC 101 ms 20308 KB
2_09.txt AC 102 ms 22740 KB
2_10.txt AC 93 ms 18772 KB
2_11.txt AC 158 ms 22612 KB
2_12.txt AC 92 ms 20564 KB
2_13.txt AC 97 ms 20820 KB
2_14.txt WA 133 ms 20308 KB
2_15.txt AC 87 ms 22996 KB
2_16.txt AC 99 ms 18900 KB
2_17.txt AC 98 ms 18900 KB
2_18.txt AC 94 ms 20436 KB
2_19.txt AC 106 ms 21844 KB
2_20.txt AC 106 ms 21204 KB
2_21.txt AC 98 ms 19028 KB
2_22.txt AC 105 ms 20308 KB