Submission #1841401
Source Code Expand
#define _CRT_SECURE_NO_WARNINGS #include <vector> #include <iostream> #include <string.h> #include <set> #include <algorithm> #include <cmath> #include <string> using namespace std; typedef double LD; typedef long long LL; typedef pair<int, int> PII; #define MP make_pair #define PB push_back #define FOR(i,a,b) for(int i = (a); i < (b); ++i) #define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i) #define REP(i, t) FOR(i,0,t) #define ALL(a) a.begin(), a.end() #define SZ(a) (int)((a).size()) const LL MOD = 1000000007; const int INF = 1e9; const LL LINF = 1LL * INF * INF; const int MAXN = 2007; const LD EPS = 1e-7; int n, A[MAXN], r = 0, P[MAXN]; bool used[MAXN]; vector <int> B[MAXN]; bool G[MAXN][MAXN]; int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } void dfs(int v, int p) { used[v] = true; if (!B[r].empty() && B[r][SZ(B[r]) - 1] != p) ++r; B[r].push_back(v); REP(i, n) { if (G[v][i] && !used[i]) dfs(i, v); } } int main() { ios_base::sync_with_stdio(0); //freopen("In.txt", "r", stdin); cin >> n; REP(i, n) cin >> A[i]; sort(A, A + n); REP(i, n) { REP(j, i) if (gcd(A[i], A[j]) > 1) G[i][j] = G[j][i] = true; } REP(i, n) if (!used[i]) dfs(i, -1); REP(i, n) { int m = 0, curr; REP(j, r + 1) { if (P[j] < SZ(B[j]) && A[B[j][P[j]]] > m) { m = A[B[j][P[j]]]; curr = j; } } cout << m << ' '; ++P[curr]; } //cout << endl; system("pause"); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Rearranging |
User | vjudge2 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1453 Byte |
Status | WA |
Exec Time | 269 ms |
Memory | 4352 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 | 267 ms | 4352 KB |
in10.txt | WA | 268 ms | 4352 KB |
in11.txt | WA | 229 ms | 4352 KB |
in12.txt | WA | 228 ms | 4352 KB |
in13.txt | WA | 226 ms | 4352 KB |
in14.txt | WA | 227 ms | 4352 KB |
in15.txt | WA | 227 ms | 4352 KB |
in16.txt | WA | 236 ms | 4352 KB |
in17.txt | AC | 236 ms | 4352 KB |
in18.txt | WA | 236 ms | 4352 KB |
in19.txt | AC | 236 ms | 4352 KB |
in2.txt | WA | 268 ms | 4352 KB |
in20.txt | WA | 236 ms | 4352 KB |
in21.txt | AC | 178 ms | 1792 KB |
in22.txt | AC | 178 ms | 1664 KB |
in23.txt | WA | 179 ms | 1792 KB |
in24.txt | AC | 178 ms | 1664 KB |
in25.txt | AC | 179 ms | 1664 KB |
in26.txt | WA | 227 ms | 4352 KB |
in27.txt | WA | 227 ms | 4352 KB |
in28.txt | WA | 225 ms | 4352 KB |
in29.txt | WA | 228 ms | 4352 KB |
in3.txt | WA | 268 ms | 4352 KB |
in30.txt | WA | 227 ms | 4352 KB |
in31.txt | AC | 1 ms | 256 KB |
in32.txt | AC | 1 ms | 384 KB |
in33.txt | AC | 1 ms | 384 KB |
in34.txt | AC | 207 ms | 384 KB |
in35.txt | AC | 207 ms | 384 KB |
in36.txt | WA | 240 ms | 4352 KB |
in37.txt | WA | 239 ms | 4352 KB |
in38.txt | WA | 240 ms | 4352 KB |
in39.txt | WA | 243 ms | 4352 KB |
in4.txt | WA | 269 ms | 4352 KB |
in40.txt | WA | 239 ms | 4352 KB |
in41.txt | WA | 240 ms | 4352 KB |
in42.txt | WA | 240 ms | 4352 KB |
in43.txt | WA | 239 ms | 4352 KB |
in44.txt | WA | 240 ms | 4352 KB |
in45.txt | WA | 241 ms | 4352 KB |
in5.txt | WA | 268 ms | 4352 KB |
in6.txt | WA | 268 ms | 4352 KB |
in7.txt | WA | 268 ms | 4352 KB |
in8.txt | WA | 269 ms | 4352 KB |
in9.txt | WA | 268 ms | 4352 KB |
sample1.txt | AC | 1 ms | 384 KB |
sample2.txt | AC | 1 ms | 384 KB |