結果

問題 No.14 最小公倍数ソート
ユーザー kou6839kou6839
提出日時 2014-11-15 21:24:53
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,044 bytes
コンパイル時間 2,344 ms
コンパイル使用メモリ 76,936 KB
実行使用メモリ 66,808 KB
最終ジャッジ日時 2023-08-30 07:04:18
合計ジャッジ時間 10,364 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
55,948 KB
testcase_01 AC 144 ms
55,744 KB
testcase_02 AC 141 ms
56,088 KB
testcase_03 AC 564 ms
61,400 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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 
class Pare implements Comparable<Pare>{
	int moto;
	int lcm;
	Pare(int moto,int lcm){
		this.moto=moto;
		this.lcm=lcm;
	}
	@Override
	public int compareTo(Pare o) {
		int res = this.lcm-o.lcm;
		if(res==0) return this.moto-o.moto;
		return res;
	}
	
}
public class Main {
	static int gcd(int a,int b){
		if(a>b){
			int temp;
			temp=a;
			a=b;
			b=temp;
		}
		while(a != 0){
			int temp=a;
			a = b%a;
			b=temp;
		}
		return b;
	}
	static int lcm(int a,int b){
		return (a*b)/gcd(a,b);
	}
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Pare[] a = new Pare[n];
    for(int i=0;i<n;i++){
    	int temp=sc.nextInt();
    	a[i]=new Pare(temp,temp);
    }
    for(int i=0;i<=n-3;i++){
    	for(int j=i+1;j<n;j++){
    		a[j].lcm=lcm(a[i].moto,a[j].moto);
    	}
    	Arrays.sort(a,i+1,n);
    }
    for(Pare f :a){
    	System.out.print(f.moto+" ");
    }
    System.out.println("");
    

    }
} 
0