# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1057657 |
2024-08-14T02:42:38 Z |
vjudge1 |
Sirni (COCI17_sirni) |
C++17 |
|
2988 ms |
397068 KB |
#include <bits/stdc++.h>
using namespace std;
#define task "test"
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define bit(s, i) (((s) >> (i)) & 1)
#define ii pair <int, int>
#define vii vector <ii>
#define vi vector <int>
#define fi first
#define se second
#define ll long long
#define eb emplace_back
#define pb push_back
#define __builtin_popcount __builtin_popcountll
void solve();
int32_t main() {
if(fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
int tc = 1; // cin >> tc;
FOR(i, 1, tc) {
solve();
}
}
const int N = 1e5+5;
int n;
vi a;
vector <pair<ii, int>> edges;
struct DSU {
int p[N];
DSU () {
fill(begin(p), end(p), 0);
}
int find(int a) {
return (p[a] == 0) ? a : p[a] = find(p[a]);
}
void unite(int a, int b) {
a = find(a); b = find(b);
if(a != b) {
p[b] = a;
}
}
} dsu;
void solve() {
cin >> n;
FOR(i, 1, n) {
int x; cin >> x;
a.eb(x);
}
sort(all(a));
a.erase(unique(all(a)), a.end());
FOR(i, 0, sz(a)-1) {
FOR(j, 2, a.back() / a[i]) {
int r = lower_bound(all(a), a[i]*j) - a.begin();
if(r < sz(a)) {
edges.pb({{i, r}, a[r] % a[i]});
j = a[r] / a[i];
}
}
}
FOR(i, 1, sz(a) - 1) edges.pb({{i-1, i}, a[i] % a[i-1]});
sort(all(edges), [] (pair <ii, int> x, pair <ii, int> y) {return x.se < y.se;});
ll cost = 0;
FOR(i, 0, sz(edges)-1) {
int u = edges[i].fi.fi, v = edges[i].fi.se, w = edges[i].se;
++u; ++v;
if(dsu.find(u) != dsu.find(v)) {
dsu.unite(u, v);
cost += w;
}
}
cout << cost;
}
Compilation message
sirni.cpp: In function 'int32_t main()':
sirni.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sirni.cpp:26:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
12 ms |
4048 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
4 ms |
1720 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
860 KB |
Output is correct |
2 |
Correct |
0 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
15164 KB |
Output is correct |
2 |
Correct |
361 ms |
50984 KB |
Output is correct |
3 |
Correct |
138 ms |
27444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
5632 KB |
Output is correct |
2 |
Correct |
155 ms |
52012 KB |
Output is correct |
3 |
Correct |
100 ms |
14924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
236 ms |
52012 KB |
Output is correct |
2 |
Correct |
466 ms |
101664 KB |
Output is correct |
3 |
Correct |
125 ms |
27008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
7248 KB |
Output is correct |
2 |
Correct |
430 ms |
101928 KB |
Output is correct |
3 |
Correct |
122 ms |
28212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
130 ms |
26424 KB |
Output is correct |
2 |
Correct |
2004 ms |
396304 KB |
Output is correct |
3 |
Correct |
153 ms |
26168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
26348 KB |
Output is correct |
2 |
Correct |
2988 ms |
397068 KB |
Output is correct |
3 |
Correct |
182 ms |
26676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
4880 KB |
Output is correct |
2 |
Correct |
2827 ms |
396596 KB |
Output is correct |
3 |
Correct |
135 ms |
27848 KB |
Output is correct |