結果
| 問題 |
No.14 最小公倍数ソート
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2015-08-22 03:01:15 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3,692 ms / 5,000 ms |
| コード長 | 1,626 bytes |
| コンパイル時間 | 653 ms |
| コンパイル使用メモリ | 92,756 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-18 12:31:32 |
| 合計ジャッジ時間 | 42,463 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <string>
//#include <array>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
LL gcd(LL a,LL b){
return b ? gcd(b,a%b) : a;
}
int A[10000];
int main(void){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
std::cout << std::fixed;//
//cout << setprecision(16);//
const int Amax = 10001;
int N;
cin>>N;
vector<int> ans(N);
int ansCount = 1;
vector<int> vec(N-1);
list<int> myList;
cin>>ans[0];
for(int i=0;i<N-1;++i){
cin>>vec[i];
}
sort( vec.begin(), vec.end() );
vector<int>::iterator titr = vec.begin();
while( titr != vec.end() ){
myList.push_back(*titr);
++titr;
}
LL ssk,tssk;
list<int>::iterator itr,minIt;
while( ansCount < N ){
itr = myList.begin();
minIt = itr;
ssk = ans[ansCount-1]/gcd(ans[ansCount-1],*itr)*(*itr);
++itr;
while( itr != myList.end() && (*itr) < ssk ){
tssk = ans[ansCount-1]/gcd(ans[ansCount-1],*itr)*(*itr);
if( tssk < ssk ){
minIt = itr;
ssk = tssk;
}
++itr;
}
ans[ansCount] = *minIt;
myList.erase(minIt);
++ansCount;
}
titr = ans.begin();
while( titr != ans.end() ){
cout << *titr;
if( titr+1 != ans.end() ){
cout << ' ';
}
++titr;
}cout << '\n';
return 0;
}
IL_msta