public void InitializeTest()
 {
     Assert.DoesNotThrow(() => StringAlgorithm.SuffixArray("".AsSpan()));
     Assert.DoesNotThrow(() => StringAlgorithm.SuffixArray <int>(Array.Empty <int>()));
     Assert.DoesNotThrow(() => StringAlgorithm.ZAlgorithm("".AsSpan()));
     Assert.DoesNotThrow(() => StringAlgorithm.ZAlgorithm <int>(Array.Empty <int>()));
 }
        public void EmptyTest()
        {
            Assert.That(StringAlgorithm.SuffixArray("".AsSpan()).Length, Is.Zero);
            Assert.That(StringAlgorithm.SuffixArray <int>(Array.Empty <int>()).Length, Is.Zero);

            Assert.That(StringAlgorithm.ZAlgorithm("".AsSpan()).Length, Is.Zero);
            Assert.That(StringAlgorithm.ZAlgorithm <int>(Array.Empty <int>()).Length, Is.Zero);
        }
Esempio n. 3
0
        public static void Solve()
        {
            var S      = Console.ReadLine();
            var sa     = StringAlgorithm.SuffixArray(S);
            var answer = (long)S.Length * (S.Length + 1) / 2;

            answer = StringAlgorithm.LongestCommonPrefixArray <char>(S, sa)
                     .Aggregate(answer, (sum, x) => sum - x);

            Console.WriteLine(answer);
        }
Esempio n. 4
0
        public static void Solve()
        {
            var S      = Scanner.Scan <string>();
            var sa     = StringAlgorithm.SuffixArray(S);
            var answer = (long)S.Length * (S.Length + 1) / 2;

            foreach (var x in StringAlgorithm.LCPArray(S, sa))
            {
                answer -= x;
            }
            Console.WriteLine(answer);
        }
Esempio n. 5
0
        /// <summary> </summary>
        public override int GetHashCode()
        {
            int hashCode = base.GetHashCode() ^ ObdGuid.GetHashCode()
                           ^ LowerLimit.GetHashCode() ^ UpperLimit.GetHashCode()
                           ^ StringAlgorithm.GetHashCode();

            if (DateRange != null)
            {
                hashCode ^= DateRange.GetHashCode();
            }

            if (!String.IsNullOrEmpty(StringInput))
            {
                hashCode ^= StringInput.GetHashCode();
            }
            return(hashCode);
        }
Esempio n. 6
0
        public static void Solve()
        {
            var N      = Scanner.Scan <int>();
            var S      = Scanner.Scan <string>();
            var answer = 0;

            for (var i = 0; i < N; i++)
            {
                var z = StringAlgorithm.ZAlgorithm(S.Substring(i)).ToArray();
                for (var j = 0; j < z.Length; j++)
                {
                    if (i + z[j] <= i + j)
                    {
                        answer = Math.Max(answer, z[j]);
                    }
                }
            }

            Console.WriteLine(answer);
        }
Esempio n. 7
0
        public static void Solve()
        {
            var N   = Scanner.Scan <int>();
            var S   = Scanner.Scan <string>();
            var sa  = StringAlgorithm.SuffixArray(S);
            var lcp = StringAlgorithm.LongestCommonPrefixArray(S, sa);

            var answer = new long[N];

            for (var i = 0; i < N; i++)
            {
                answer[i] = N - i;
            }

            for (var k = 0; k < 2; k++)
            {
                var stack = new Stack <(long H, long W)>();
                var s     = 0L;
                for (var i = 0; i < N - 1; i++)
                {
                    var w = 1L;
                    while (stack.TryPeek(out var top) && top.H > lcp[i])
                    {
                        w += top.W;
                        s -= top.H * top.W;
                        stack.Pop();
                    }

                    s += lcp[i] * w;
                    stack.Push((lcp[i], w));
                    answer[sa[i + 1]] += s;
                }

                Array.Reverse(sa);
                Array.Reverse(lcp);
            }

            Console.WriteLine(string.Join("\n", answer));
        }
        public void SuffixArrayTest()
        {
            const string str    = "missisippi";
            var          sa     = StringAlgorithm.SuffixArray(str);
            var          answer = new[]
            {
                "i",          // 9
                "ippi",       // 6
                "isippi",     // 4
                "issisippi",  // 1
                "missisippi", // 0
                "pi",         // 8
                "ppi",        // 7
                "sippi",      // 5
                "sisippi",    // 3
                "ssisippi"    // 2
            };

            Assert.That(sa.Length, Is.EqualTo(answer.Length));
            for (var i = 0; i < sa.Length; i++)
            {
                Assert.That(str[sa[i]..], Is.EqualTo(answer[i]));