結果
| 問題 | No.39 桁の数字を入れ替え | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-07-25 17:48:08 | 
| 言語 | C# (.NET 8.0.404) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 57 ms / 5,000 ms | 
| コード長 | 1,793 bytes | 
| コンパイル時間 | 15,529 ms | 
| コンパイル使用メモリ | 168,204 KB | 
| 実行使用メモリ | 184,352 KB | 
| 最終ジャッジ日時 | 2024-10-02 11:24:18 | 
| 合計ジャッジ時間 | 15,383 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 | 
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (149 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/
ソースコード
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);
                }
            }
        }
    }
}
            
            
            
        