# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
782050 |
2023-07-13T15:06:50 Z |
Ahmed57 |
Sirni (COCI17_sirni) |
C++17 |
|
1981 ms |
137164 KB |
//#pragma GCC optimize("Ofast,O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
using namespace std;
//DSU
int mn = 100001;
int pr[100001];
int gs[100001];
int findleader(int x){
if(pr[x]==x){
return x;
}
return pr[x] = findleader(pr[x]);
}
bool mergegroup(int x,int y){
int led1 = findleader(x);
int led2 = findleader(y);
if(led1==led2)return 0;
if(gs[led1]>gs[led2]){
pr[led2]=led1;
gs[led1]+=gs[led2];
}else{
pr[led1]=led2;
gs[led2]+=gs[led1];
}
return 1;
}
vector<pair<long long,pair<int,int>>> ans;
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n;
cin>>n;
set<int> s;
int ma = 0;
for(int i = 0;i<n;i++){
int x;cin>>x;
s.insert(x);
ma = max(ma,x);
}
assert(ma<=1e6);
vector<int> arr;
for(auto i:s)arr.push_back(i);
n = arr.size();
for(int i = 0;i<n;i++)pr[i] = i , gs[i] = 1;
for(int i = 0;i<n;i++){
int j = i+1;
for(int e = arr[i];e<=ma;e+=arr[i]){
while(j<n&&arr[j]<e)j++;
if(j<n)ans.push_back({arr[j]%arr[i],{i,j}});
}
}
sort(ans.begin(),ans.end());
long long all = 0;
for(int i = 0;i<ans.size();i++){
if(mergegroup(ans[i].second.first,ans[i].second.second))all+=ans[i].first;
}
cout<<all<<"\n";
return 0;
}
Compilation message
sirni.cpp: In function 'int main()':
sirni.cpp:56:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i = 0;i<ans.size();i++){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1345 ms |
38852 KB |
Output is correct |
2 |
Correct |
1698 ms |
71228 KB |
Output is correct |
3 |
Correct |
1061 ms |
70640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
5316 KB |
Output is correct |
2 |
Correct |
333 ms |
66616 KB |
Output is correct |
3 |
Correct |
952 ms |
37892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1520 ms |
71608 KB |
Output is correct |
2 |
Correct |
1981 ms |
137164 KB |
Output is correct |
3 |
Correct |
1364 ms |
38708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
207 ms |
10688 KB |
Output is correct |
2 |
Correct |
1851 ms |
136116 KB |
Output is correct |
3 |
Correct |
1125 ms |
38200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
29 ms |
9932 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
31 ms |
9940 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
2388 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |