結果

問題 No.14 最小公倍数ソート
ユーザー ciel
提出日時 2014-11-16 17:23:05
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 487 bytes
コンパイル時間 562 ms
コンパイル使用メモリ 44,928 KB
実行使用メモリ 10,024 KB
最終ジャッジ日時 2024-12-31 20:39:21
合計ジャッジ時間 70,214 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12 TLE * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         scanf("%d",&n);
      |         ~~~~~^~~~~~~~~
main.cpp:12:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         for(int i=0;i<n;i++)scanf("%d",&v[i].second);
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x/gcd(x,y)*y;}
int main(){
	int n,s=0;
	scanf("%d",&n);
	vector<pair<int,int> >v(n);
	for(int i=0;i<n;i++)scanf("%d",&v[i].second);
	for(int i=0;i<n-2;i++){
		for(int j=i+1;j<n;j++)v[j].first=lcm(v[i].second,v[j].second);
		sort(v.begin()+i+1,v.end());
	}
	for(int i=0;i<n;i++)printf(i<n-1?"%d ":"%d\n",v[i].second);
}
0