Submission #1131211
Source Code Expand
using System; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Diagnostics; using System.Numerics; using Enu = System.Linq.Enumerable; public class Program { static readonly int INF = (int)1e9; int N; public void Solve() { N = Reader.Int(); if (N > 3) throw new Exception(); var grid = Reader.StringArray(N).Select(r => r.ToCharArray()).ToArray(); int ans = BFS(grid); Console.WriteLine(ans == INF ? -1 : ans); } private int BFS(char[][] grid) { var set = new HashSet<int>(); int initialMask = 0; for (int r = 0; r < N; r++) for (int c = 0; c < N; c++) initialMask |= ".#".IndexOf(grid[r][c]) << (r * N + c); set.Add(initialMask); int want = (1 << N * N) -1; for (int steps = 0; steps < 8; steps++) { var nset = new HashSet<int>(); foreach (int g in set) { if (g == want) return steps; for (int selR = 0; selR < N; selR++) for (int selC = 0; selC < N; selC++) { var nextg = g; for (int i = 0; i < N; i++) { nextg &= ~(1 << (i * N + selC)); nextg |= (g >> (selR * N + i) & 1) << (i * N + selC); } nset.Add(nextg); } } set = nset; } return INF; } } class Entry { static void Main() { new Program().Solve(); } } class Reader { static TextReader reader = Console.In; static readonly char[] separator = { ' ' }; static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; static string[] A = new string[0]; static int i; static void Init() { A = new string[0]; } public static void Set(TextReader r) { reader = r; Init(); } public static void Set(string file) { reader = new StreamReader(file); Init(); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Range(N, Int); } public static int[][] IntTable(int H) { return Range(H, IntLine); } public static string[] StringArray(int N) { return Range(N, Next); } public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); } public static string Line() { return reader.ReadLine().Trim(); } public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; } static string[] Split(string s) { return s.Split(separator, op); } static string Next() { CheckNext(); return A[i++]; } static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }
Submission Info
Submission Time | |
---|---|
Task | B - Row to Column |
User | eitaho |
Language | C# (Mono 4.6.2.0) |
Score | 300 |
Code Size | 3514 Byte |
Status | RE |
Exec Time | 29 ms |
Memory | 13536 KB |
Judge Result
Set Name | Sample | Subtask | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | 0 / 1000 | ||||||||
Status |
|
|
|
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 | 28 ms | 9440 KB |
0_01.txt | AC | 27 ms | 11604 KB |
0_02.txt | AC | 28 ms | 11488 KB |
0_03.txt | AC | 28 ms | 11488 KB |
0_04.txt | AC | 29 ms | 13536 KB |
1_00.txt | AC | 27 ms | 9440 KB |
1_01.txt | AC | 28 ms | 13536 KB |
1_02.txt | AC | 28 ms | 11604 KB |
1_03.txt | AC | 28 ms | 9440 KB |
1_04.txt | AC | 28 ms | 11488 KB |
1_05.txt | AC | 28 ms | 11488 KB |
1_06.txt | AC | 28 ms | 13536 KB |
1_07.txt | AC | 28 ms | 11584 KB |
1_08.txt | AC | 28 ms | 11488 KB |
1_09.txt | AC | 28 ms | 9440 KB |
1_10.txt | AC | 27 ms | 9440 KB |
1_11.txt | AC | 27 ms | 9440 KB |
1_12.txt | AC | 27 ms | 9440 KB |
1_13.txt | AC | 27 ms | 11488 KB |
1_14.txt | AC | 28 ms | 11488 KB |
2_00.txt | RE | 20 ms | 8672 KB |
2_01.txt | RE | 20 ms | 10720 KB |
2_02.txt | RE | 20 ms | 10720 KB |
2_03.txt | RE | 20 ms | 8672 KB |
2_04.txt | RE | 20 ms | 10720 KB |
2_05.txt | RE | 21 ms | 12768 KB |
2_06.txt | RE | 20 ms | 10720 KB |
2_07.txt | RE | 20 ms | 10720 KB |
2_08.txt | RE | 20 ms | 10720 KB |
2_09.txt | RE | 21 ms | 12768 KB |
2_10.txt | RE | 20 ms | 10720 KB |
2_11.txt | RE | 20 ms | 10720 KB |
2_12.txt | RE | 20 ms | 10720 KB |
2_13.txt | RE | 20 ms | 10720 KB |
2_14.txt | RE | 20 ms | 10720 KB |
2_15.txt | RE | 20 ms | 10720 KB |
2_16.txt | RE | 20 ms | 10720 KB |
2_17.txt | RE | 20 ms | 10720 KB |
2_18.txt | RE | 20 ms | 10720 KB |
2_19.txt | RE | 20 ms | 8672 KB |
2_20.txt | RE | 21 ms | 12768 KB |
2_21.txt | RE | 20 ms | 10720 KB |
2_22.txt | RE | 20 ms | 8672 KB |