結果
| 問題 |
No.14 最小公倍数ソート
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2015-08-22 07:47:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,146 bytes |
| コンパイル時間 | 652 ms |
| コンパイル使用メモリ | 88,404 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-18 12:33:40 |
| 合計ジャッジ時間 | 28,502 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 WA * 17 |
ソースコード
#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;
}
const int Amax = 10001;
int Ymax=0;
int A[Amax];
int main(void){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
std::cout << std::fixed;//
//cout << setprecision(16);//
int N;
cin>>N;
vector<int> ans(N);
int ansCount = 1;
cin>>ans[0];
int temp;
for(int i=0;i<N-1;++i){
cin>>temp;
Ymax = max(Ymax,temp+1);
++A[temp];
}
int count = 1;
int min = 1;
int it = 1;
bool flag = true;
while( ansCount < N ){
for(count = min; count<Ymax; ++count){
if( A[count] ){
min = count;
break;
}
}
if( ans[ansCount-1] == 1){//?
ans[ansCount] = min;
--A[min];
++ansCount;
flag = true;
}else if( flag && ans[ansCount-1] < min ){
for(int i= ans[ansCount-1];i<Ymax;i+=i ){
if( A[i] ){
while(A[i]){
ans[ansCount] = i;
++ansCount;
--A[i];
}
}
}
flag = false;
}else {
int minID = min;
LL ssk = ans[ansCount-1]/gcd(ans[ansCount-1],minID)*minID;
LL temp;
for(count = min; count < ssk && count<Ymax; ++count){
if( A[count] ){
temp = ans[ansCount-1]/gcd(ans[ansCount-1],count)*count;
if( temp < ssk){
ssk = temp;
minID = count;
}
}
}
if( ans[ansCount-1] == minID ){
while( A[minID] ){
ans[ansCount] = minID;
++ansCount;
--A[minID];
}
}else{
ans[ansCount] = minID;
++ansCount;
--A[minID];
}
flag = true;
}
}
vector<int>::iterator titr;
titr = ans.begin();
while( titr != ans.end() ){
cout << *titr;
if( titr+1 != ans.end() ){
cout << ' ';
}
++titr;
}cout << '\n';
return 0;
}
IL_msta