結果
| 問題 |
No.14 最小公倍数ソート
|
| ユーザー |
14番
|
| 提出日時 | 2016-05-29 10:21:07 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,145 bytes |
| コンパイル時間 | 1,009 ms |
| コンパイル使用メモリ | 114,252 KB |
| 実行使用メモリ | 31,720 KB |
| 最終ジャッジ日時 | 2024-10-07 17:38:37 |
| 合計ジャッジ時間 | 8,058 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 TLE * 1 -- * 15 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
}
}
14番