I passed the first test set with my code, but the second test set gives me 
WA.
As far as I can tell, my code is correct. Can anyone show me otherwise?

Code is in C#.

using System;
using System.Collections.Generic;

namespace KickStartGoogle {
    class Program {
        static void Main(string[] args) {
            int testCases = int.Parse(Console.ReadLine());
            for (int i = 0; i < testCases; i++) {
                performTest(i + 1);
            }
        }

        public static void performTest(int testCase) {
            string[] rc = Console.ReadLine().Split(' ');
            string[] wall = new string[int.Parse(rc[0])];
            List<char> pol = new List<char>();
            var finalwall = new string[int.Parse(rc[0])];
            string order = "";
            for (int i = 0; i < int.Parse(rc[0]); i++) {
                wall[i] = Console.ReadLine();
                finalwall[i] = makeStringOfLength(int.Parse(rc[1]));
                foreach (var c in wall[i]) {
                    if (!pol.Contains(c)) pol.Add(c);
                }
            }

            bool polAdded = false;
            do {
                polAdded = false;
                for (int i = 0; i < pol.Count; i++) {
                    polAdded = false;
                    var tmpWall = new string[int.Parse(rc[0])];
                    finalwall.CopyTo(tmpWall, 0);
                    for (int j = 0; j < wall.Length; j++) {
                        for (int k = 0; k < wall[j].Length; k++) {
                            if (wall[j][k] == pol[i]) {
                                var ca = tmpWall[j].ToCharArray();
                                ca[k] = pol[i];
                                tmpWall[j] = new string(ca);
                            }
                        }
                    }
                    if (isStable(tmpWall)) {
                        tmpWall.CopyTo(finalwall, 0);
                        order += pol[i];
                        pol.RemoveAt(i);
                        i--;
                        polAdded = true;
                    }

                }
            } while (polAdded);
            if (pol.Count > 0)
                Console.WriteLine("Case #" + testCase + ": -1");
            else
                Console.WriteLine("Case #" + testCase + ": " + order);
        }

        public static string makeStringOfLength(int len) {
            string s = "";
            for (int i = 0; i < len; i++) {
                s += '.';
            }
            return s;
        }

        public static bool isStable(string[] wall) {
            for (int i = 0; i < wall.Length; i++) {
                for (int j = 0; j < wall[i].Length; j++) {
                    if (wall[i][j] != '.') {
                        for (int k = i + 1; k < wall.Length; k++) {
                            if (wall[k][j] == '.') return false;
                        }
                    }
                }
            }
            return true;
        }
    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/ffa5d778-a29d-466b-ab52-63d39fa20095%40googlegroups.com.

Reply via email to