結果

問題 No.39 桁の数字を入れ替え
ユーザー 抹茶アイス抹茶アイス
提出日時 2023-07-25 17:48:08
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 54 ms / 5,000 ms
コード長 1,793 bytes
コンパイル時間 8,463 ms
コンパイル使用メモリ 166,568 KB
実行使用メモリ 184,852 KB
最終ジャッジ日時 2024-04-10 09:35:28
合計ジャッジ時間 10,283 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
30,080 KB
testcase_01 AC 51 ms
30,080 KB
testcase_02 AC 54 ms
30,208 KB
testcase_03 AC 52 ms
29,952 KB
testcase_04 AC 52 ms
29,824 KB
testcase_05 AC 52 ms
29,824 KB
testcase_06 AC 52 ms
29,824 KB
testcase_07 AC 51 ms
30,080 KB
testcase_08 AC 51 ms
30,080 KB
testcase_09 AC 50 ms
29,952 KB
testcase_10 AC 50 ms
29,824 KB
testcase_11 AC 51 ms
29,568 KB
testcase_12 AC 50 ms
29,568 KB
testcase_13 AC 50 ms
29,824 KB
testcase_14 AC 49 ms
29,952 KB
testcase_15 AC 48 ms
29,824 KB
testcase_16 AC 48 ms
29,952 KB
testcase_17 AC 49 ms
29,824 KB
testcase_18 AC 47 ms
184,852 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (86 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  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 System.Collections.Generic;
using System.Linq;

namespace yukicoder
{
    public class Program
    {
        public static void Main()
        {
            var n = Console.ReadLine();
            var max = int.Parse(n);
            var k = Combination.Generate(n.Length, 2, false);
            foreach(var x in k)
            {
                var a = n[x[0]];
                var b = n[x[1]];
                var m = n.Remove(x[0], 1).Insert(x[0], b.ToString()).Remove(x[1], 1).Insert(x[1], a.ToString());
                max = max < int.Parse(m) ? int.Parse(m) : max;
            }
            Console.WriteLine(max);
        }
        static class Combination
        {
            private static List<List<int>> _comb;
            public static List<List<int>> Generate(int n, int r, bool dupulication)
            {
                _comb = new List<List<int>>();
                CalcCombination(new List<int>(), n, r, dupulication);
                return _comb;
            }
            private static void CalcCombination(List<int> list, int n, int r, bool dupulication)
            {
                if (list.Count == r)
                {
                    _comb.Add(new List<int>(list));
                    return;
                }
                var index = 0;
                if (dupulication)
                {
                    index = list.Any() ? list.Last() : 0;
                }
                else
                {
                    index = list.Any() ? list.Last() + 1 : 0;
                }
                for (int i = index; i < n; i++)
                {
                    list.Add(i);
                    CalcCombination(list, n, r, dupulication);
                    list.Remove(i);
                }
            }
        }
    }
}
0