Apparently this is not for the problem Cryptopangrams.

I am not C# expert, but I guess it is because adding a char to the end of a 
string is not constant time operation. Try using StringBuilder instead.

The following code will pass.


using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

namespace Problem1 
{ 
    class Program 
    { 
        static void Main(string[] args) 
        { 

            string numCases = Console.ReadLine(); 
            int n = Int32.Parse(numCases.Trim()); 

            for (int i = 0; i < n; i++) 
            { 

                int sizeMaze = Int32.Parse(Console.ReadLine()); 
                string pathEnemy = Console.ReadLine(); 
                StringBuilder sb = new StringBuilder("", sizeMaze);
                for (int j = 0; j < pathEnemy.Length; j++) 
                { 
                    if (pathEnemy[j] == 'S') sb.Append("E"); 
                    else sb.Append("S");
                } 

                Console.WriteLine("Case #" + (i + 1) + ": " + sb.ToString()); 
            } 
        } 
    } 
} 

在 2019年4月8日星期一 UTC-7下午1:40:47,Peter Chikov写道:
> My solution follows the analysis and still times out(TLE).
> 
> using System;
> using System.Collections.Generic;
> using System.IO;
> using System.Linq;
> using System.Text;
> using System.Threading.Tasks;
> 
> namespace Problem1
> {
>     class Program
>     {
>         static void Main(string[] args)
>         {
> 
>             string numCases = Console.ReadLine();
>             int n = Int32.Parse(numCases.Trim());
> 
>             for (int i = 0; i < n; i++)
>             {
> 
>                 int sizeMaze = Int32.Parse(Console.ReadLine());
>                 string pathEnemy = Console.ReadLine();
>                 string path = "";
>                 for (int j = 0; j < pathEnemy.Length; j++)
>                 {
>                     if (pathEnemy[j] == 'S') path += 'E';
>                     else path += 'S';
>                 }
> 
>                 Console.WriteLine("Case #" + (i + 1) + ": " + path);
>             }
>         }
>     }
> }

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/3fbea297-d74a-42e6-88ce-0d45855bc865%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to