# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1106864 |
2024-10-31T08:11:58 Z |
vjudge1 |
Sirni (COCI17_sirni) |
C++17 |
|
3584 ms |
397516 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 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);
solve();
}
const int N = 1e5+5;
int n;
vector <int> p;
vector <pair <ii, int>> edge;
struct DSU {
int par[N];
void init(int n) {
iota(par, par+n, 0);
}
int find(int a) {
return par[a] == a ? a : par[a] = find(par[a]);
}
void unite(int a, int b) {
a = find(a); b = find(b);
if(a != b) {
par[b] = a;
}
}
} dsu;
void solve() {
cin >> n;
p.resize(n);
for(int &i:p) cin >> i;
sort(all(p));
p.erase(unique(all(p)), p.end());
FOR(i, 0, sz(p)-1) {
int it = i + 1;
while(it < sz(p)) {
edge.pb({{i, it}, p[it] % p[i]});
int valnxt = (p[it]/p[i] + 1) * p[i];
it = lower_bound(all(p), valnxt) - p.begin();
}
}
FOR(i, 0, sz(p)-2) {
edge.pb({{i, i+1}, p[i+1]%p[i]});
}
sort(all(edge), [] (pair <ii, int> x, pair <ii, int> y) {return x.se < y.se;});
dsu.init(sz(p));
ll ans = 0;
for(pair <ii, int> e:edge) {
if(dsu.find(e.fi.fi) != dsu.find(e.fi.se)) {
ans = ans + e.se;
dsu.unite(e.fi.fi, e.fi.se);
}
}
cout << ans << '\n';
}
Compilation message
sirni.cpp: In function 'int32_t main()':
sirni.cpp:23:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sirni.cpp:24:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
16 ms |
4036 KB |
Output is correct |
3 |
Correct |
3 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
6 ms |
1360 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
138 ms |
27764 KB |
Output is correct |
2 |
Correct |
440 ms |
52156 KB |
Output is correct |
3 |
Correct |
166 ms |
27564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
4036 KB |
Output is correct |
2 |
Correct |
187 ms |
52184 KB |
Output is correct |
3 |
Correct |
142 ms |
27600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
52188 KB |
Output is correct |
2 |
Correct |
558 ms |
101328 KB |
Output is correct |
3 |
Correct |
161 ms |
27516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
7868 KB |
Output is correct |
2 |
Correct |
552 ms |
101536 KB |
Output is correct |
3 |
Correct |
157 ms |
27560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
27560 KB |
Output is correct |
2 |
Correct |
2437 ms |
396772 KB |
Output is correct |
3 |
Correct |
189 ms |
27576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
152 ms |
27616 KB |
Output is correct |
2 |
Correct |
3584 ms |
396932 KB |
Output is correct |
3 |
Correct |
235 ms |
28332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
4036 KB |
Output is correct |
2 |
Correct |
3425 ms |
397516 KB |
Output is correct |
3 |
Correct |
171 ms |
28332 KB |
Output is correct |