요게 더 빠른 코드 이해가 안감 배열크기가 720000 360000 인데

using System;

using System.IO;

using System.Collections.Generic;

using System.Text;

namespace ThisIsCShaps

{

    class Program

    {

        static StreamReader sr = new StreamReader(Console.OpenStandardInput());

        static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());

        static string[] str;

        static int answer = 0,n;

        static int[] arr, arr2;

        static List<int> GetTable(string pattern)

        {

            int size = pattern.Length;

            List<int> table = new List<int>();

            for (int i = 0; i < size; i++)

            {

                table.Add(0);

            }

            int j = 0;

            for (int i =1; i < size; i++)

            {

                while(j>0&&!pattern[i].Equals(pattern[j]))

                {

                    j = table[j - 1];

                }

                if(pattern[i].Equals(pattern[j]))

                {

                    j++;

                    table[i] = j;

                }

            }

            return table;

        }

        static bool IsSame(string p,string p2)

        {

            List<int> table = GetTable(p2);

            int size = p.Length;

            int j = 0;

            for (int i = 0; i < size; i++)

            {

                while(j>0&&!p[i].Equals(p2[j]))

                {

                    j = table[j - 1];

                }

                if(p[i].Equals(p2[j]))

                {

                    if(j.Equals(p2.Length-1))

                    {

                        //있다.

                        j = table[j];

                        return true;

                    }

                    else

                    {

                    j++;

                    }

                }

            }

            return false;

        }

        static void Main(string[] args)

        {

            n = int.Parse(sr.ReadLine());

            arr = new int[360000*2];

            arr2 = new int[360000];

            str = sr.ReadLine().Split();

           StringBuilder p1=new StringBuilder(), p2=new StringBuilder();

            for (int i = 0; i < str.Length; i++)

            {

                int idx = int.Parse(str[i]);

               arr[idx]=1;

                arr[idx+360000] = 1;

            }

            for (int i = 0; i < arr.Length; i++)

            {

                if (arr[i].Equals(1))

                {

                    p1.Append('1');

                }

                else

                {

                    p1.Append('0');

                }

            }

            str = sr.ReadLine().Split();

            for (int i = 0; i < str.Length; i++)

            {

                int idx = int.Parse(str[i]);

                arr2[idx] = 1;

            }

            for (int i = 0; i < arr2.Length; i++)

            {

                if (arr2[i].Equals(1))

                {

                    p2.Append('1');

                }

                else

                {

                    p2.Append('0');

                }

            }

           if(IsSame(p1.ToString(),p2.ToString()))

            {

                sw.Write("possible");

            }

           else

            {

                sw.Write("impossible");

            }

            sw.Close();

        }

    }

}



이게 string으로 StringBuilder 사용해서 만든거 사용한 코드 이게 더 빠름

이게 무조건 더 계산이 많은데

이거 말고


using System;

using System.IO;

using System.Collections.Generic;

using System.Text;

namespace ThisIsCShaps

{

    class Program

    {

        static StreamReader sr = new StreamReader(Console.OpenStandardInput());

        static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());

        static string[] str;

        static int answer = 0,n;

        static int[] arr, arr2;

        static List<int> GetTable(int[] arrs)

        {

            int size = arrs.Length;

            List<int> table = new List<int>();

            for (int i = 0; i < size; i++)

            {

                table.Add(0);

            }

            int j = 0;

            for (int i =1; i < size; i++)

            {

                while(j>0&&!arrs[i].Equals(arrs[j]))

                {

                    j = table[j - 1];

                }

                if(arrs[i].Equals(arrs[j]))

                {

                    j++;

                    table[i] = j;

                }

            }

            return table;

        }

        static bool IsSame()

        {

            List<int> table = GetTable(arr2);

            int size = arr.Length;

            int j = 0;

            for (int i = 0; i < size; i++)

            {

                while(j>0&&!arr[i].Equals(arr2[j]))

                {

                    j = table[j - 1];

                }

                if(arr[i].Equals(arr2[j]))

                {

                    if(j.Equals(arr2.Length-1))

                    {

                        //있다.

                        j = table[j];

                        return true;

                    }

                    else

                    {

                    j++;

                    }

                }

            }

            return false;

        }

        static void Main(string[] args)

        {

            n = int.Parse(sr.ReadLine());

            arr = new int[360000*2];

            arr2 = new int[360000];

            str = sr.ReadLine().Split();

           StringBuilder p1=new StringBuilder(), p2=new StringBuilder();

            for (int i = 0; i < str.Length; i++)

            {

                int idx = int.Parse(str[i]);

               arr[idx]=1;

                arr[idx +360000] = 1;

            }

            for (int i = 0; i < arr.Length; i++)

            {

                if (arr[i].Equals(1))

                {

                    p1.Append('1');

                }

                else

                {

                    p1.Append('0');

                }

            }

            str = sr.ReadLine().Split();

            for (int i = 0; i < str.Length; i++)

            {

                int idx = int.Parse(str[i]);

                arr2[idx] = 1;

            }

            for (int i = 0; i < arr2.Length; i++)

            {

                if (arr2[i].Equals(1))

                {

                    p2.Append('1');

                }

                else

                {

                    p2.Append('0');

                }

            }

           if(IsSame())

            {

                sw.Write("possible");

            }

           else

            {

                sw.Write("impossible");

            }

            sw.Close();

        }

    }

}


이게 더 느림;;
밑에껀 스샷하려다 귀찮아서 ㅈㅅ