# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
948763 |
2024-03-18T13:20:00 Z |
May27_th |
Sirni (COCI17_sirni) |
C++17 |
|
1867 ms |
747088 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;
struct Edge{
int u, v, c;
};
void Solve(){
int N; cin >> N;
vector<int> P(N);
for (auto &x : P) cin >> x;
sort (P.begin(), P.end());
P.erase(unique(P.begin(), P.end()), P.end());
N = P.size();
vector<int> pos(P.back() + 4, -1);
for (int i = 0; i < N; i ++) {
pos[P[i]] = i;
}
for (int i = P.back() - 1; i >= 0; i --) {
if (pos[i] == -1) {
pos[i] = pos[i + 1];
}
}
vector<vector<pair<int, int>>> G(P.back() + 2);
for (int i = 0; i < N - 1; i ++) {
//ve.push_back({i, i + 1, min(P[i], P[i + 1] % P[i])});
G[P[i + 1] % P[i]].push_back(make_pair(i, i + 1));
for (int j = 2 * P[i]; j <= P.back(); j += P[i]) {
//ve.push_back({i, pos[j], min(P[pos[j]] % P[i], P[i])});
G[P[pos[j]] % P[i]].push_back(make_pair(i, pos[j]));
}
} /*sort (ve.begin(), ve.end(), [&] (Edge &a, Edge &b){
return a.c < b.c;
});*/
int64_t ans = 0; DSU d(N + 10);
for (int c = 0; c <= P.back(); c ++) {
for (auto [i, j] : G[c]) {
if (d.unite(i, j)) {
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 |
Correct |
119 ms |
274260 KB |
Output is correct |
2 |
Correct |
186 ms |
302420 KB |
Output is correct |
3 |
Correct |
106 ms |
273492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1125 ms |
668932 KB |
Output is correct |
3 |
Correct |
111 ms |
275116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
274464 KB |
Output is correct |
2 |
Correct |
105 ms |
273784 KB |
Output is correct |
3 |
Correct |
108 ms |
274564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
38284 KB |
Output is correct |
2 |
Correct |
104 ms |
70144 KB |
Output is correct |
3 |
Correct |
63 ms |
49124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
29788 KB |
Output is correct |
2 |
Correct |
72 ms |
50896 KB |
Output is correct |
3 |
Correct |
37 ms |
24668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
49804 KB |
Output is correct |
2 |
Correct |
131 ms |
87004 KB |
Output is correct |
3 |
Correct |
58 ms |
47276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
9680 KB |
Output is correct |
2 |
Correct |
133 ms |
86160 KB |
Output is correct |
3 |
Correct |
61 ms |
49720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
288428 KB |
Output is correct |
2 |
Correct |
1202 ms |
633488 KB |
Output is correct |
3 |
Correct |
174 ms |
291976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
184 ms |
292320 KB |
Output is correct |
2 |
Correct |
1867 ms |
747088 KB |
Output is correct |
3 |
Correct |
311 ms |
348452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
276736 KB |
Output is correct |
2 |
Correct |
1802 ms |
634664 KB |
Output is correct |
3 |
Correct |
63 ms |
53824 KB |
Output is correct |