結果

問題 No.14 最小公倍数ソート
ユーザー 14番14番
提出日時 2016-05-29 10:21:07
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,145 bytes
コンパイル時間 1,074 ms
コンパイル使用メモリ 114,372 KB
実行使用メモリ 31,592 KB
最終ジャッジ日時 2024-04-16 18:15:00
合計ジャッジ時間 7,915 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
25,300 KB
testcase_01 AC 30 ms
19,200 KB
testcase_02 AC 30 ms
19,200 KB
testcase_03 AC 129 ms
19,584 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int numCount = int.Parse(Reader.ReadLine());

        int[] numList = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

        int[] ans = new int[numCount];


        List<int> subList = new List<int>(numList);
        ans[0] = numList[0];
        subList.RemoveAt(0);
        for (int i = 1; i < numList.Length; i++)
        {
            int minIdx = 0;
            long minNum = long.MaxValue;

            for (int j = 0; j < subList.Count; j++)
            {
                long koubai = GetKoubai(ans[i - 1], subList[j]);
                if (koubai < minNum)
                {
                    minIdx = j;
                    minNum = koubai;
                }
                else if (koubai == minNum && subList[j] < subList[minIdx])
                {
                    minIdx = j;
                }
            }
            ans[i] = subList[minIdx];
            subList.RemoveAt(minIdx);
        }
        Console.WriteLine(string.Join(" ", ans));

    }

    private long GetKoubai(int num1, int num2)
    {
        long a = Math.Max(num1, num2);
        long b = Math.Min(num1, num2);

        while (a % b > 0)
        {
            long tmp = a % b;
            a = b;
            b = tmp;
        }
        return ((num1 / b) * num2);
    }




    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


10
9 9 3 7 5 9 1 5 2 1



 
";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }

    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0