Submission #1191490


Source Code Expand

import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();

		char[][] a = new char[n][];
		for (int i = 0; i < n; i++) {
			a[i] = sc.next().toCharArray();
		}

		int[] cntr = new int[n];
		int[] cnth = new int[n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (a[i][j] == '#') {
					cnth[i]++;
					cntr[j]++;
				}
			}
		}

		int ret1 = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			if (cntr[i] == 0) {
				continue;
			}

			for (int j = 0; j < n; j++) {
				ret1 = Math.min(ret1, n - cnth[i]);
			}
		}

		int ret2 = 0;
		for (int j = 0; j < n; j++) {
			if (cntr[j] < n) {
				ret2++;
			}
		}

		if (ret2 == 0) {
			pr.println(0);
		} else {
			if (ret1 == Integer.MAX_VALUE) {
				pr.println(-1);
			} else {
				pr.println(ret2 + ret1);
			}
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		private boolean isPrintable(int ch) {
			return ch >= '!' && ch <= '~';
		}

		private boolean isCRLF(int ch) {
			return ch == '\n' || ch == '\r' || ch == -1;
		}

		private int nextPrintable() {
			try {
				int ch;
				while (!isPrintable(ch = br.read())) {
					if (ch == -1) {
						throw new NoSuchElementException();
					}
				}

				return ch;
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		String next() {
			try {
				int ch = nextPrintable();
				StringBuilder sb = new StringBuilder();
				do {
					sb.appendCodePoint(ch);
				} while (isPrintable(ch = br.read()));

				return sb.toString();
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		int nextInt() {
			try {
				// parseInt from Integer.parseInt()
				boolean negative = false;
				int res = 0;
				int limit = -Integer.MAX_VALUE;
				int radix = 10;

				int fc = nextPrintable();
				if (fc < '0') {
					if (fc == '-') {
						negative = true;
						limit = Integer.MIN_VALUE;
					} else if (fc != '+') {
						throw new NumberFormatException();
					}
					fc = br.read();
				}
				int multmin = limit / radix;

				int ch = fc;
				do {
					int digit = ch - '0';
					if (digit < 0 || digit >= radix) {
						throw new NumberFormatException();
					}
					if (res < multmin) {
						throw new NumberFormatException();
					}
					res *= radix;
					if (res < limit + digit) {
						throw new NumberFormatException();
					}
					res -= digit;

				} while (isPrintable(ch = br.read()));

				return negative ? res : -res;
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		long nextLong() {
			try {
				// parseLong from Long.parseLong()
				boolean negative = false;
				long res = 0;
				long limit = -Long.MAX_VALUE;
				int radix = 10;

				int fc = nextPrintable();
				if (fc < '0') {
					if (fc == '-') {
						negative = true;
						limit = Long.MIN_VALUE;
					} else if (fc != '+') {
						throw new NumberFormatException();
					}
					fc = br.read();
				}
				long multmin = limit / radix;

				int ch = fc;
				do {
					int digit = ch - '0';
					if (digit < 0 || digit >= radix) {
						throw new NumberFormatException();
					}
					if (res < multmin) {
						throw new NumberFormatException();
					}
					res *= radix;
					if (res < limit + digit) {
						throw new NumberFormatException();
					}
					res -= digit;

				} while (isPrintable(ch = br.read()));

				return negative ? res : -res;
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		float nextFloat() {
			return Float.parseFloat(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			try {
				int ch;
				while (isCRLF(ch = br.read())) {
					if (ch == -1) {
						throw new NoSuchElementException();
					}
				}
				StringBuilder sb = new StringBuilder();
				do {
					sb.appendCodePoint(ch);
				} while (!isCRLF(ch = br.read()));

				return sb.toString();
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new NoSuchElementException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}

Submission Info

Submission Time
Task B - Row to Column
User garnacha
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 4848 Byte
Status WA
Exec Time 134 ms
Memory 28244 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 74 ms 21204 KB
0_01.txt AC 71 ms 19668 KB
0_02.txt AC 71 ms 18772 KB
0_03.txt AC 70 ms 19540 KB
0_04.txt AC 73 ms 18516 KB
1_00.txt AC 75 ms 21204 KB
1_01.txt AC 74 ms 21588 KB
1_02.txt AC 72 ms 20820 KB
1_03.txt AC 74 ms 21460 KB
1_04.txt AC 76 ms 19028 KB
1_05.txt AC 71 ms 21076 KB
1_06.txt WA 70 ms 18260 KB
1_07.txt AC 74 ms 21588 KB
1_08.txt AC 71 ms 19156 KB
1_09.txt AC 73 ms 20180 KB
1_10.txt AC 72 ms 21460 KB
1_11.txt AC 71 ms 21204 KB
1_12.txt AC 71 ms 22996 KB
1_13.txt AC 72 ms 18004 KB
1_14.txt AC 72 ms 19540 KB
2_00.txt AC 129 ms 24276 KB
2_01.txt AC 130 ms 24500 KB
2_02.txt AC 125 ms 24148 KB
2_03.txt AC 124 ms 26196 KB
2_04.txt AC 122 ms 26196 KB
2_05.txt AC 129 ms 26324 KB
2_06.txt WA 126 ms 25172 KB
2_07.txt AC 127 ms 25684 KB
2_08.txt AC 133 ms 25044 KB
2_09.txt AC 131 ms 26324 KB
2_10.txt AC 127 ms 25940 KB
2_11.txt AC 120 ms 25300 KB
2_12.txt AC 134 ms 28116 KB
2_13.txt AC 125 ms 23892 KB
2_14.txt WA 132 ms 25812 KB
2_15.txt AC 133 ms 26196 KB
2_16.txt AC 124 ms 26196 KB
2_17.txt AC 122 ms 22740 KB
2_18.txt AC 129 ms 28244 KB
2_19.txt AC 133 ms 24244 KB
2_20.txt AC 128 ms 27220 KB
2_21.txt AC 131 ms 24148 KB
2_22.txt AC 127 ms 26292 KB