# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1106860 |
2024-10-31T08:07:17 Z |
vjudge1 |
Sirni (COCI17_sirni) |
C++14 |
|
642 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;
int n, a[nx], par[nx];
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();
vector<int> last(rar.back() + 100, 0);
for(int i = 1; i <= n; i++)
a[i]=rar[i-1], last[a[i]]=i;
for(int i = a[n] - 1; i >= 1; i--)
{
if(last[i])
continue;
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;
}
Compilation message
sirni.cpp: In function 'int main()':
sirni.cpp:41:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
41 | if(last[i])
| ^~
sirni.cpp:43:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
43 | last[i]=last[i+1];
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
39504 KB |
Output is correct |
2 |
Correct |
193 ms |
90804 KB |
Output is correct |
3 |
Correct |
17 ms |
39916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Runtime error |
555 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
39760 KB |
Output is correct |
2 |
Correct |
12 ms |
39504 KB |
Output is correct |
3 |
Correct |
16 ms |
39700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
146 ms |
32052 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
8180 KB |
Output is correct |
2 |
Correct |
271 ms |
56760 KB |
Output is correct |
3 |
Incorrect |
141 ms |
30212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
302 ms |
56624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
49 ms |
8772 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
195 ms |
67536 KB |
Output is correct |
2 |
Runtime error |
575 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
239 ms |
67312 KB |
Output is correct |
2 |
Runtime error |
642 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
43524 KB |
Output is correct |
2 |
Runtime error |
627 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |