結果
| 問題 |
No.14 最小公倍数ソート
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2015-08-22 07:01:41 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,956 bytes |
| コンパイル時間 | 887 ms |
| コンパイル使用メモリ | 94,472 KB |
| 実行使用メモリ | 13,880 KB |
| 最終ジャッジ日時 | 2024-07-18 12:32:52 |
| 合計ジャッジ時間 | 7,683 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 TLE * 1 -- * 15 |
ソースコード
#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];
const int NumMax = 10000;
bool pdp[NumMax+1];
vector<int> prime;
void makePrime(int N=NumMax){
for(int i=2; i<= N; ++i){
if(pdp[i] == false){
prime.push_back(i);
for(int j = i+i; j<= N; j += i){
pdp[j] = true;
}
}
}
return ;
}
int main(void){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
std::cout << std::fixed;//
//cout << setprecision(16);//
const int Amax = 10001;
makePrime();
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;
}
myList.push_back(Amax);
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 != Amax && (*itr) < ssk ){
tssk = ans[ansCount-1]/gcd(ans[ansCount-1],*itr)*(*itr);
if( tssk < ssk ){
minIt = itr;
ssk = tssk;
}
//++itr;
itr = upper_bound(itr,myList.end(),(*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