# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1106881 |
2024-10-31T08:31:04 Z |
vjudge1 |
Sirni (COCI17_sirni) |
C++14 |
|
743 ms |
786432 KB |
#include <bits/stdc++.h>
#define ii pair<int, int>
#define fi first
#define se second
using namespace std;
using ll = long long;
const int nx=1e5+5;
const int N=1e7+5;
int n, a[N], last[N], par[N];
ll ans=0;
vector<int> rar;
vector<pair<int, ii>> ed;
int find(int u)
{
if(!par[u])
return u;
return par[u]=find(par[u]);
}
bool join(int u, int v)
{
u=find(u);
v=find(v);
if(u==v)
return 0;
par[v]=u;
return 1;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n;
for(int i = 1; i <= n; i++)
cin>>a[i], rar.emplace_back(a[i]);
sort(rar.begin(), rar.end());
rar.erase(unique(rar.begin(), rar.end()), rar.end());
n=rar.size();
for(int i = 1; i <= n; i++)
{
a[i]=rar[i-1];
last[a[i]]=i;
}
for(int i = N-2; i >= 1; i--)
{
if(last[i])
continue;
if(last[i+1])
last[i]=last[i+1];
}
for(int i = 1; i <= n; i++)
{
if(last[a[i]+1])
ed.push_back({a[last[a[i]+1]]%a[i], {i, last[a[i]+1]}});
for(int j = 2*a[i]; j <= a[n]; j+=a[i])
if(last[j])
ed.push_back({a[last[j]]%a[i], {i, last[j]}});
}
sort(ed.begin(), ed.end());
for(auto it:ed)
if(join(it.se.fi, it.se.se))
ans+=it.fi;
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
41552 KB |
Output is correct |
2 |
Correct |
198 ms |
94948 KB |
Output is correct |
3 |
Correct |
13 ms |
44060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
6656 KB |
Output is correct |
2 |
Runtime error |
632 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
41552 KB |
Output is correct |
2 |
Correct |
18 ms |
41560 KB |
Output is correct |
3 |
Correct |
14 ms |
43792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
36148 KB |
Output is correct |
2 |
Correct |
581 ms |
60712 KB |
Output is correct |
3 |
Correct |
248 ms |
60728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
12532 KB |
Output is correct |
2 |
Correct |
290 ms |
60720 KB |
Output is correct |
3 |
Correct |
161 ms |
34108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
316 ms |
60720 KB |
Output is correct |
2 |
Correct |
743 ms |
109852 KB |
Output is correct |
3 |
Correct |
221 ms |
35992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
14160 KB |
Output is correct |
2 |
Correct |
738 ms |
109928 KB |
Output is correct |
3 |
Correct |
221 ms |
36148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
70972 KB |
Output is correct |
2 |
Runtime error |
616 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
224 ms |
70964 KB |
Output is correct |
2 |
Runtime error |
658 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
47364 KB |
Output is correct |
2 |
Runtime error |
652 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |