Hi,

I am participating for the code jam 2019 for first time and for practice I have 
solved the  2018 qualification round 'Saving the Universe again' problem using 
C#. and I am getting the correct outputs. But when i submit the problem, its 
showing wrong answer. I dont know what else do i need to add the code as there 
are few hours left to begin the competitions. 

Can you please help what is wrong?. Here is my raw code.



using System;


namespace ConsoleApp1
{
    class Program
    {
        static void Main()
        {
            
            //BasicTest();- 1

            var T = int.Parse(Console.ReadLine());
            for (int i = 0; i < T; i++)
            {
                var DP = Console.ReadLine();
                var splitDP = DP.Split(' ');
                var D = int.Parse(splitDP[0]);
                var P = splitDP[1];
                var mH = 0;
                var b = 1;
                var s =0;
                var c = 0;
                int sum = 0;
                var nP = string.Empty;
                var sC = P.Replace("c", "").Length;
                
                if (sC > D)
                {
                    Console.WriteLine("Case #" + (i + 1) + ": " + "IMPOSSIBLE");

                    continue;
                }
                if (!P.Contains("c"))
                {
                   
                        Console.WriteLine("Case #" + (i + 1) + ": " + mH);
                   
                }
                else
                {
                    
                        sum=CountSum(P,s,b,c,sum);
                        while(sum>D)
                        {
                            mH++;
                            var temp = P.IndexOf("cs");
                            var subP = P.Substring(temp, 2);
                            var arr = subP.ToCharArray();
                            Array.Reverse(arr);
                            subP = new string(arr);
                            P =P.Substring(0,temp)+ subP+ P.Substring(temp+2, 
P.Length-(temp + 2));
                            
                            sum=CountSum(P, 0, 1, 0, 0);
                        }

                        Console.WriteLine("Case #" + (i + 1) + ": " + mH);
                   

                }
            }
            Console.ReadLine(); 

        }
        public static int CountSum(string P, int s, int b, int c, int sum)
        {
            for (int j = 0; j < P.Length; j++)
            {
                if (P[j] == 's')
                {
                    s = b;
                    b = s;
                    sum = sum + s;
                }
                else
                {
                    c = 2 * b;
                    b = c;
                }
            }
            return sum;
        }

        //public static void BasicTest()
        //{
        //    var T = int.Parse(Console.ReadLine());
        //    for (int t = 0; t < T; t++)
        //    {

        //        var N = int.Parse(Console.ReadLine());
        //        var Arr = Console.ReadLine();
        //        var X = Console.ReadLine();
        //        if (!Arr.Contains(X))
        //            Console.WriteLine("-1");
        //        var strArr = Arr.Split(' ');
        //        findElement(strArr, X);


        //    }
        //    Console.ReadKey();
        //}
        //public static void findElement(string[] strArr, string X)
        //{
        //    Console.WriteLine(Array.IndexOf(strArr, X, 0));
        //}
    }
}

-- 
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 google-code+unsubscr...@googlegroups.com.
To post to this group, send email to google-code@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/ae1b24c4-f754-43b9-94aa-009470fbc1ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to