結果

問題 No.1059 素敵な集合
ユーザー Kiyoshi MorohashiKiyoshi Morohashi
提出日時 2024-01-22 14:11:48
言語 C#
(.NET 8.0.203)
結果
WA  
実行時間 -
コード長 1,434 bytes
コンパイル時間 6,598 ms
コンパイル使用メモリ 158,596 KB
実行使用メモリ 181,104 KB
最終ジャッジ日時 2024-01-22 14:12:01
合計ジャッジ時間 12,744 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 RE -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 WA -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (97 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;

class Program
{
    static void Main(string[] args)
    {
        // L と R を入力する
        //Console.WriteLine("L を入力してください:");
        string[] L_R = Console.ReadLine().Split(' ');
        int L = int.Parse(L_R[0]);
        //Console.WriteLine("R を入力してください:");
        int R = int.Parse(L_R[1]);

        // 集合 S を作成する
        int[] S = new int[R - L + 1];
        for (int i = 0; i < S.Length; i++)
        {
            S[i] = i + L;
        }

        // すべての組み合わせに対してコストを計算し、メモリに保存する
        int[,] costs = new int[R - L + 1, R - L + 1];
        for (int i = 0; i < costs.GetLength(0); i++)
        {
            for (int j = 0; j < costs.GetLength(1); j++)
            {
                costs[i, j] = S[i] % S[j];
            }
        }

        // 最小コストを求める
        int minCost = int.MaxValue;
        for (int i = 0; i < costs.GetLength(0); i++)
        {
            for (int j = 0; j < costs.GetLength(1); j++)
            {
                // 最小コストを更新する
                if (costs[i, j] < minCost)
                {
                    minCost = costs[i, j];
                }
            }
        }

        // 結果を出力する
        //Console.WriteLine("最小コストは {0} です。", minCost);
        Console.WriteLine(minCost);
    }
}
0