結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー 👑 kakel-sankakel-san
提出日時 2024-01-26 01:05:53
言語 C#
(.NET 8.0.203)
結果
WA  
実行時間 -
コード長 2,232 bytes
コンパイル時間 7,142 ms
コンパイル使用メモリ 158,616 KB
実行使用メモリ 194,976 KB
最終ジャッジ日時 2024-01-26 01:06:05
合計ジャッジ時間 11,424 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
32,804 KB
testcase_01 AC 84 ms
32,804 KB
testcase_02 AC 76 ms
32,548 KB
testcase_03 AC 78 ms
32,804 KB
testcase_04 AC 78 ms
32,804 KB
testcase_05 AC 78 ms
32,804 KB
testcase_06 AC 78 ms
32,804 KB
testcase_07 AC 77 ms
32,932 KB
testcase_08 AC 77 ms
32,932 KB
testcase_09 AC 78 ms
32,932 KB
testcase_10 AC 79 ms
32,932 KB
testcase_11 AC 85 ms
32,932 KB
testcase_12 AC 79 ms
32,932 KB
testcase_13 AC 85 ms
32,932 KB
testcase_14 AC 78 ms
32,932 KB
testcase_15 AC 78 ms
32,932 KB
testcase_16 AC 129 ms
47,524 KB
testcase_17 AC 126 ms
47,524 KB
testcase_18 AC 122 ms
47,524 KB
testcase_19 AC 118 ms
47,524 KB
testcase_20 AC 116 ms
47,524 KB
testcase_21 AC 115 ms
47,524 KB
testcase_22 WA -
testcase_23 AC 99 ms
42,404 KB
testcase_24 AC 116 ms
44,964 KB
testcase_25 AC 97 ms
42,404 KB
testcase_26 AC 122 ms
194,976 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (100 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.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[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray();
    static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = ReadLine().Split();
        var n = int.Parse(c[0]);
        var a = NList;
        WriteLine(Sort(n, c[1], a));
    }
    static string Sort(int n, string _k, int[] _a)
    {;
        var k = _k.Select(ci => ci - '0').ToArray();
        var a = _a.ToList();
        a.Insert(0, 0);
        var max = new List<int>(n);
        for (var i = 9; i >= 0; --i) for (var j = 0; j < a[i]; ++j) max.Add(i);
        if (!IsLarge(max, k))
        {
            return "-1";
        }
        var pos = 0;
        var ans = new List<int>(n);
        while (pos < n)
        {
            if (a[k[pos]] > 0)
            {
                ans.Add(k[pos]);
                --a[k[pos]];
            }
            else break;
            ++pos;
        }
        while (true)
        {
            if (ans.Count < n)
            {
                var flg = false;
                for (var i = k[ans.Count] + 1; i < a.Count; ++i) if (a[i] > 0)
                {
                    ans.Add(i);
                    --a[i];
                    flg = true;
                    break;
                }
                if (flg) break;
            }
            ++a[ans[^1]];
            ans.RemoveAt(ans.Count - 1);
        }
        for (var i = 0; i < a.Count; ++i) for (var j = 0; j < a[i]; ++j) ans.Add(i);
        return string.Concat(ans);
    }
    static bool IsLarge(List<int> m, int[] k)
    {
        if (m.Count > k.Length) return true;
        if (m.Count < k.Length) return false;
        for (var i = 0; i < m.Count; ++i)
        {
            if (m[i] > k[i]) return true;
            if (m[i] < k[i]) return false;
        }
        return false;
    }
}
0