結果

問題 No.3290 Encrypt Failed, but Decrypt Succeeded
ユーザー kakel-san
提出日時 2025-10-03 23:12:53
言語 C#
(.NET 8.0.404)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 3,608 bytes
コンパイル時間 10,362 ms
コンパイル使用メモリ 170,024 KB
実行使用メモリ 196,568 KB
最終ジャッジ日時 2025-10-03 23:13:19
合計ジャッジ時間 14,050 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (104 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    static int[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray();
    static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray();
    static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var s = ReadLine().Split();
        var n = int.Parse(s[0]);
        var k = long.Parse(s[1]);
        --k;
        var t = ReadLine();
        var count = new long[n + 1];
        count[n] = 1;
        var INF = long.MaxValue / 3;
        for (var i = n - 1; i >= 0; --i)
        {
            if (i + 1 == n)
            {
                count[i] = 1;
            }
            else
            {
                if (t[i] == '0')
                {
                    // 00 ~ 09
                }
                else if ((t[i] == '1' || t[i] == '2') && t[i + 1] == '0')
                {
                    // 10, 20
                    count[i] = count[i + 2];
                }
                else if (t[i] == '1' || (t[i] == '2' && t[i + 1] <= '6'))
                {
                    // 11~19, 21~26
                    count[i] = count[i + 1] + count[i + 2];
                }
                else
                {
                    count[i] = count[i + 1];
                }
            }
            if (count[i] > 1_000_000_000_000_000_000) count[i] = INF;
        }
        var ans = new List<char>();
        for (var i = 0; i < n; ++i)
        {
            if (i + 1 == n)
            {
                ans.Add(ToAlpha(t[i]));
            }
            else
            {
                if ((t[i] == '1' || t[i] == '2') && t[i + 1] == '0')
                {
                    // 10, 20
                    ans.Add(ToAlpha(t[i], t[i + 1]));
                    ++i;
                }
                else if (t[i] == '1' || (t[i] == '2' && t[i + 1] <= '6'))
                {
                    // 11~19, 21~26
                    if (k < count[i + 1])
                    {
                        ans.Add(ToAlpha(t[i]));
                    }
                    else
                    {
                        ans.Add(ToAlpha(t[i], t[i + 1]));
                        k -= count[i + 1];
                        ++i;
                    }
                }
                else
                {
                    ans.Add(ToAlpha(t[i]));
                }
            }
        }
        WriteLine(string.Concat(ans));
    }
    static char ToAlpha(char ti)
    {
        return (char)(ti - '1' + 'a');
    }
    static char ToAlpha(char ti, char tj)
    {
        return (char)((ti - '1' + 1) * 10 + tj - '1' + 'a');
    }
    static void DFS(int n, int cur, long k, string t, long[] dp)
    {
        if (cur + 1 == n)
        {
            dp[cur] = 1;
        }
        else if (cur + 2 == n)
        {
            if (t[cur] > '2' || (t[cur] == '2' && t[cur + 1] > '6'))
            {
                DFS(n, cur + 1, k, t, dp);
                dp[cur] = dp[cur + 1];
            }
            else
            {

            }
        }
    }
}
0