Submission #1096333
Source Code Expand
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <vector> #include <string> #include <algorithm> #include <stack> #include <queue> #include <set> #include <map> using namespace std; #define MOD @ #define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD) typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec; int gcd(int a, int b) { while (b) { int t = a % b; a = b; b = t; } return a; } int N, A[2020]; vector<int> dv[2020]; vector<int> rdiv[50505]; int RC; bool isok[2020], used[2020]; bool rdivvis[50505]; bool vis[2020]; bool chk(int iic) { for (int i = 0; i < N; ++i) vis[i] = false; for (int i = 0; i < RC; ++i) rdivvis[i] = false; queue<int> Qa, Qb; // place [0, iic] first // printf("chk %d\n", A[iic]); for (int i = 0; i <= iic; ++i) if (!used[i] && isok[i]) { Qa.push(i); vis[i] = true; } while (!Qa.empty()) { int v = Qa.front(); Qa.pop(); for (int p : dv[v]) if (!rdivvis[p]) { rdivvis[p] = true; for (int i : rdiv[p]) if (!used[i] && !vis[i]) { vis[i] = true; if (i <= iic) Qa.push(i); else Qa.push(i); } } } /* while (!Qb.empty()) { int v = Qb.front(); Qb.pop(); for (int p : dv[v]) if (!rdivvis[p]) { rdivvis[p] = true; for (int i : rdiv[p]) if (!used[i] && !vis[i]) { vis[i] = true; if (i <= iic) { puts("><"); exit(0); } else Qb.push(i); } } } */ for (int i = 0; i < N; ++i) if (!used[i] && !vis[i]) return false; return true; } int main() { scanf("%d", &N); for (int i = 0; i < N; ++i) { scanf("%d", A + i); } sort(A, A + N); for (int i = 0; i < N; ++i) { int v = A[i]; for (int j = 2; j * j <= v; ++j) { if (v % j == 0) { dv[i].push_back(j); while (v % j == 0) v /= j; } } if (v > 1) dv[i].push_back(v); } vector<int> alldv; for (int i = 0; i < N; ++i) { for (int p : dv[i]) alldv.push_back(p); } sort(alldv.begin(), alldv.end()); alldv.erase(unique(alldv.begin(), alldv.end()), alldv.end()); for (int i = 0; i < N; ++i) { for (int &p : dv[i]) { p = lower_bound(alldv.begin(), alldv.end(), p) - alldv.begin(); rdiv[p].push_back(i); } } RC = alldv.size(); for (int i = 0; i < N; ++i) { isok[i] = true; used[i] = false; } vector<int> ans; for (int i = 0; i < N; ++i) { vector<int> cand; for (int j = 0; j < N; ++j) if (!used[j]) cand.push_back(j); int left = 0, right = cand.size() - 1; while (left < right) { int mid = (left + right) / 2; if (chk(cand[mid])) { right = mid; } else { left = mid + 1; } } int v = A[cand[left]]; ans.push_back(v); // printf("%d\n", v); used[cand[left]] = true; for (int j = 0; j < N; ++j) { if (A[j] > v) { isok[j] = false; } if (gcd(A[j], v) != 1) { isok[j] = true; } } } for (int i = 0; i < N; ++i) printf("%d%c", ans[i], i == N - 1 ? '\n' : ' '); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Rearranging |
User | semiexp |
Language | C++14 (GCC 5.4.1) |
Score | 1600 |
Code Size | 3027 Byte |
Status | AC |
Exec Time | 1169 ms |
Memory | 1792 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:80:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &N); ^ ./Main.cpp:82:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", A + i); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1600 / 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 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | AC | 1150 ms | 1664 KB |
in10.txt | AC | 1169 ms | 1664 KB |
in11.txt | AC | 963 ms | 1664 KB |
in12.txt | AC | 970 ms | 1664 KB |
in13.txt | AC | 960 ms | 1664 KB |
in14.txt | AC | 964 ms | 1664 KB |
in15.txt | AC | 955 ms | 1664 KB |
in16.txt | AC | 1126 ms | 1664 KB |
in17.txt | AC | 1128 ms | 1664 KB |
in18.txt | AC | 1127 ms | 1664 KB |
in19.txt | AC | 1132 ms | 1792 KB |
in2.txt | AC | 1154 ms | 1664 KB |
in20.txt | AC | 1124 ms | 1664 KB |
in21.txt | AC | 570 ms | 1664 KB |
in22.txt | AC | 566 ms | 1664 KB |
in23.txt | AC | 567 ms | 1664 KB |
in24.txt | AC | 563 ms | 1664 KB |
in25.txt | AC | 564 ms | 1664 KB |
in26.txt | AC | 960 ms | 1664 KB |
in27.txt | AC | 962 ms | 1664 KB |
in28.txt | AC | 960 ms | 1664 KB |
in29.txt | AC | 974 ms | 1664 KB |
in3.txt | AC | 1154 ms | 1664 KB |
in30.txt | AC | 966 ms | 1664 KB |
in31.txt | AC | 4 ms | 1536 KB |
in32.txt | AC | 4 ms | 1536 KB |
in33.txt | AC | 4 ms | 1536 KB |
in34.txt | AC | 585 ms | 1664 KB |
in35.txt | AC | 585 ms | 1664 KB |
in36.txt | AC | 1021 ms | 1664 KB |
in37.txt | AC | 1018 ms | 1664 KB |
in38.txt | AC | 1026 ms | 1664 KB |
in39.txt | AC | 1027 ms | 1664 KB |
in4.txt | AC | 1151 ms | 1664 KB |
in40.txt | AC | 1020 ms | 1664 KB |
in41.txt | AC | 1016 ms | 1664 KB |
in42.txt | AC | 1024 ms | 1664 KB |
in43.txt | AC | 1015 ms | 1664 KB |
in44.txt | AC | 1017 ms | 1664 KB |
in45.txt | AC | 1023 ms | 1664 KB |
in5.txt | AC | 1146 ms | 1664 KB |
in6.txt | AC | 1140 ms | 1664 KB |
in7.txt | AC | 1153 ms | 1664 KB |
in8.txt | AC | 1156 ms | 1664 KB |
in9.txt | AC | 1154 ms | 1664 KB |
sample1.txt | AC | 4 ms | 1536 KB |
sample2.txt | AC | 4 ms | 1536 KB |