# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
990876 |
2024-05-31T17:04:39 Z |
BF001 |
Sirni (COCI17_sirni) |
C++17 |
|
128 ms |
369240 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define N 100005
#define se second
#define fi first
int n, par[N], res = 0;
vector<int> p;
struct ii
{
int u, v, w;
bool operator < (ii o){
return w < o.w;
}
};
int find(int u){
if (u == par[u]) return u;
return par[u] = find(par[u]);
}
void unin(int u, int v, int w){
u = find(u);
v = find(v);
if (u == v) return;
par[u] = v;
res += w;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++){
int val;
par[i] = i;
cin >> val;
p.push_back(val);
}
sort(p.begin(), p.end());
p.resize(unique(p.begin(), p.end()) - p.begin());
int ma = p.back();
vector<int> near(ma + 1, -1);
vector<vector<pair<int, int>>> eg(ma + 1);
for (int i = 0; i < (int) p.size(); i++){
near[p[i]] = i + 1;
}
for (int i = ma - 1; i >= 1; i--){
if (near[i] == -1) near[i] = near[i + 1];
}
for (int i = 0; i < (int) p.size(); i++){
eg[(p[i + 1] % p[i])].push_back({i + 1, i + 2});
for (int j = 2 * p[i]; j <= ma; j += p[i]){
int pos = near[j];
if (pos == -1) continue;
eg[p[pos - 1] % p[i]].push_back({i + 1, pos});
}
}
for (int i = 0; i <= ma; i++){
for (auto x : eg[i]){
unin(x.fi, x.se, i);
}
}
cout << res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
313428 KB |
Output is correct |
2 |
Incorrect |
128 ms |
369240 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
313428 KB |
Output is correct |
2 |
Correct |
61 ms |
312916 KB |
Output is correct |
3 |
Correct |
64 ms |
313692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
52556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
35524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
84 ms |
82680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
14024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
127 ms |
340564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
126 ms |
350652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
72 ms |
318136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |