Submission #44498953


Source Code Expand

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;

namespace Tasks;

public class C
{
    public static void Main()
    {
        using var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }

    public static void Solve()
    {
        var (N, M) = Scanner.Scan<int, int>();
        var S = Scanner.Scan<string>();
        var C = Scanner.ScanEnumerable<int>().ToArray();
        var ID = new List<int>[M + 1].Select(_ => new List<int>()).ToArray();
        for (var i = 0; i < N; i++)
        {
            ID[C[i]].Add(i);
        }

        var T = S.ToCharArray();
        for (var i = 1; i <= M; i++)
        {
            if (ID[i].Count <= 1) continue;
            var idx = ID[i];
            var prev = T[idx[0]];
            for (var j = 1; j < idx.Count; j++)
            {
                var tmp = T[idx[j]];
                T[idx[j]] = prev;
                prev = tmp;
            }

            T[idx[0]] = prev;
        }

        var answer = new string(T);
        Console.WriteLine(answer);
    }

    public static class Scanner
    {
        public static T Scan<T>() where T : IConvertible => Convert<T>(ScanStringArray()[0]);
        public static (T1, T2) Scan<T1, T2>() where T1 : IConvertible where T2 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]));
        }
        public static (T1, T2, T3) Scan<T1, T2, T3>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]));
        }
        public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]));
        }
        public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]), Convert<T5>(input[4]));
        }
        public static (T1, T2, T3, T4, T5, T6) Scan<T1, T2, T3, T4, T5, T6>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible where T6 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]), Convert<T5>(input[4]), Convert<T6>(input[5]));
        }
        public static IEnumerable<T> ScanEnumerable<T>() where T : IConvertible => ScanStringArray().Select(Convert<T>);
        private static string[] ScanStringArray()
        {
            var line = Console.ReadLine()?.Trim() ?? string.Empty;
            return string.IsNullOrEmpty(line) ? Array.Empty<string>() : line.Split(' ');
        }
        private static T Convert<T>(string value) where T : IConvertible => (T)System.Convert.ChangeType(value, typeof(T));
    }
}

Submission Info

Submission Time
Task C - Rotate Colored Subsequence
User AconCavy
Language C# 11.0 (.NET 7.0.7)
Score 300
Code Size 3574 Byte
Status AC
Exec Time 105 ms
Memory 62668 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 29
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 55 ms 26472 KiB
001.txt AC 82 ms 44484 KiB
002.txt AC 101 ms 62668 KiB
003.txt AC 82 ms 44796 KiB
004.txt AC 77 ms 46912 KiB
005.txt AC 93 ms 49624 KiB
006.txt AC 65 ms 34380 KiB
007.txt AC 66 ms 35268 KiB
008.txt AC 72 ms 36076 KiB
009.txt AC 105 ms 62164 KiB
010.txt AC 82 ms 49060 KiB
011.txt AC 79 ms 47008 KiB
012.txt AC 74 ms 46908 KiB
013.txt AC 79 ms 46428 KiB
014.txt AC 76 ms 47364 KiB
015.txt AC 76 ms 44816 KiB
016.txt AC 79 ms 47176 KiB
017.txt AC 76 ms 44568 KiB
018.txt AC 74 ms 45176 KiB
019.txt AC 81 ms 44808 KiB
020.txt AC 82 ms 45184 KiB
021.txt AC 80 ms 44660 KiB
022.txt AC 72 ms 44660 KiB
023.txt AC 72 ms 45012 KiB
024.txt AC 77 ms 44444 KiB
025.txt AC 80 ms 44500 KiB
026.txt AC 76 ms 44568 KiB
example0.txt AC 58 ms 26400 KiB
example1.txt AC 54 ms 26456 KiB