# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
948712 |
2024-03-18T12:11:41 Z |
May27_th |
Sirni (COCI17_sirni) |
C++17 |
|
1339 ms |
47012 KB |
#include<bits/stdc++.h>
#define taskname "a"
using namespace std;
void World_Final();
void Solve();
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
if (fopen(taskname".in", "r")) {
freopen(taskname".in", "r", stdin);
freopen(taskname".out", "w", stdout);
}
World_Final();
}
void World_Final(){
int Tests = 1;
//cin >> Tests;
for (int i = 1; i <= Tests; i ++) {
//cout << i << "\n";
Solve();
}
}
struct DSU{
private:
vector<int> par, sz;
public:
int ccp;
DSU(int N) : par(N + 5), sz(N + 5) {
ccp = N;
for (int i = 1; i <= N; i ++) {
par[i] = i;
sz[i] = 1;
}
}
/*void init(int N) {
par.resize(N + 5); sz.resize(N + 5);
for (int i = 1; i <= N; i ++) {
par[i] = i; sz[i] = 1;
}
}*/
int findPar(int u) {
return (u == par[u] ? u : par[u] = findPar(par[u]));
}
//int getSize(int u) { return sz[findPar(u)]; }
bool same(int u, int v) {
return findPar(u) == findPar(v);
}
bool unite(int u, int v) {
int paru = findPar(u);
int parv = findPar(v);
if (paru == parv) return false;
if (sz[paru] < sz[parv]) swap(paru, parv);
sz[paru] += sz[parv];
par[parv] = paru;
return true;
}
};
const int MAXN = 1e5 + 10;
const int64_t INF = 1e18;
int N, M, K;
struct Edge{
int u, v, c;
};
void Solve(){
cin >> N;
vector<Edge> ve;
int mx = 1e7 + 10;
vector<int> P(N), pos(mx, -1);
for (auto &x : P) cin >> x;
sort (P.begin(), P.end());
for (int i = 0; i < N; i ++) {
pos[P[i]] = i;
if (i) {
ve.push_back({i, i - 1, min(P[i] % P[i - 1], P[i - 1])});
ve.push_back({i, 0, min(P[i] % P[0], P[0])});
}
for (int j = 1; j * j <= P[i]; j ++) {
if (P[i] % j == 0) {
if (pos[j] >= 0) {
ve.push_back({i, pos[j], 0});
if (P[i]/j != j) {
if (pos[P[i]/j] >= 0) {
ve.push_back({i, pos[P[i]/j], 0});
}
}
}
}
}
} sort (ve.begin(), ve.end(), [&] (Edge &a, Edge &b){
return a.c < b.c;
});
int64_t ans = 0; DSU d(N);
for (auto [u, v, c] : ve) {
if (d.unite(u, v)) {
ans += c;
}
} cout << ans;
}
Compilation message
sirni.cpp: In function 'int main()':
sirni.cpp:11:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | freopen(taskname".in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
sirni.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | freopen(taskname".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
39508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
39632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
39628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
428 ms |
44236 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
67 ms |
40116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
414 ms |
47012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
82 ms |
41544 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1337 ms |
43932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1339 ms |
43916 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
272 ms |
40752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |