Submission #1502875
Source Code Expand
#include <bits/stdc++.h>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))
using namespace std;
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
// Problem Specific Parameter:
vector<int> a;
const int limit = 100010;
vector<int> graph[limit];
bool visited[limit];
deque<int> ans[limit];
void dfs(int v){
visited[v] = true;
for(auto &v2:graph[v]){
if(visited[v2]) continue;
dfs(v2);
while(!ans[v2].empty()){
ans[v].push_front(ans[v2].back());
ans[v2].pop_back();
}
}
ans[v].push_front(a[v]);
}
int main(void){
int n;
cin >> n;
a.resize(n);
rep(i,n) cin >> a[i];
sort(begin(a),end(a));
rep(i,n)rep(j,n){
if(i==j or __gcd(a[i],a[j])==1) continue;
graph[i].push_back(j);
}
rep(i,n) graph[n].push_back(i);
dfs(n);
ans[n].pop_front();
rep(i,n) cout << (i?" ":"") << ans[n][i];
cout << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
E - Rearranging |
User |
Hec |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1911 Byte |
Status |
WA |
Exec Time |
554 ms |
Memory |
85888 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 1600 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample1.txt, sample2.txt |
All |
sample1.txt, sample2.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in3.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in4.txt, in40.txt, in41.txt, in42.txt, in43.txt, in44.txt, in45.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt |
Case Name |
Status |
Exec Time |
Memory |
in1.txt |
WA |
551 ms |
79232 KB |
in10.txt |
WA |
552 ms |
79744 KB |
in11.txt |
WA |
481 ms |
71424 KB |
in12.txt |
WA |
484 ms |
71424 KB |
in13.txt |
WA |
481 ms |
71424 KB |
in14.txt |
WA |
483 ms |
71424 KB |
in15.txt |
WA |
482 ms |
71424 KB |
in16.txt |
AC |
484 ms |
85888 KB |
in17.txt |
AC |
483 ms |
85888 KB |
in18.txt |
AC |
482 ms |
85760 KB |
in19.txt |
AC |
483 ms |
85760 KB |
in2.txt |
WA |
551 ms |
79232 KB |
in20.txt |
AC |
483 ms |
85888 KB |
in21.txt |
AC |
371 ms |
69888 KB |
in22.txt |
AC |
372 ms |
69888 KB |
in23.txt |
AC |
376 ms |
69888 KB |
in24.txt |
AC |
371 ms |
69888 KB |
in25.txt |
AC |
371 ms |
69888 KB |
in26.txt |
WA |
482 ms |
71424 KB |
in27.txt |
WA |
483 ms |
71424 KB |
in28.txt |
WA |
479 ms |
71424 KB |
in29.txt |
WA |
487 ms |
71424 KB |
in3.txt |
WA |
551 ms |
78976 KB |
in30.txt |
WA |
482 ms |
71424 KB |
in31.txt |
AC |
40 ms |
69888 KB |
in32.txt |
AC |
40 ms |
69888 KB |
in33.txt |
AC |
40 ms |
69888 KB |
in34.txt |
AC |
427 ms |
69888 KB |
in35.txt |
AC |
428 ms |
69888 KB |
in36.txt |
WA |
502 ms |
72832 KB |
in37.txt |
WA |
501 ms |
72832 KB |
in38.txt |
AC |
503 ms |
72832 KB |
in39.txt |
WA |
504 ms |
72832 KB |
in4.txt |
WA |
552 ms |
78976 KB |
in40.txt |
WA |
501 ms |
72704 KB |
in41.txt |
WA |
502 ms |
72832 KB |
in42.txt |
WA |
504 ms |
72832 KB |
in43.txt |
WA |
502 ms |
72832 KB |
in44.txt |
AC |
503 ms |
72704 KB |
in45.txt |
WA |
504 ms |
72832 KB |
in5.txt |
WA |
550 ms |
78976 KB |
in6.txt |
WA |
552 ms |
79488 KB |
in7.txt |
WA |
551 ms |
79616 KB |
in8.txt |
WA |
553 ms |
79360 KB |
in9.txt |
WA |
554 ms |
78976 KB |
sample1.txt |
AC |
40 ms |
69888 KB |
sample2.txt |
AC |
39 ms |
69888 KB |