# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
782044 |
2023-07-13T15:03:11 Z |
Ahmed57 |
Sirni (COCI17_sirni) |
C++17 |
|
1954 ms |
786432 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;
}
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);
}
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;
vector<pair<long long,pair<int,int>>> ans;
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:55: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]
55 | for(int i = 0;i<ans.size();i++){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
259 ms |
66148 KB |
Output is correct |
3 |
Correct |
3 ms |
976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Runtime error |
991 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1381 ms |
38788 KB |
Output is correct |
2 |
Correct |
1635 ms |
71196 KB |
Output is correct |
3 |
Correct |
1125 ms |
70536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
5316 KB |
Output is correct |
2 |
Correct |
381 ms |
66636 KB |
Output is correct |
3 |
Correct |
957 ms |
37852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1562 ms |
71580 KB |
Output is correct |
2 |
Correct |
1954 ms |
137136 KB |
Output is correct |
3 |
Correct |
1311 ms |
38668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
203 ms |
10636 KB |
Output is correct |
2 |
Correct |
1886 ms |
136052 KB |
Output is correct |
3 |
Correct |
1110 ms |
38188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1429 ms |
39032 KB |
Output is correct |
2 |
Runtime error |
911 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1465 ms |
39080 KB |
Output is correct |
2 |
Runtime error |
879 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
5700 KB |
Output is correct |
2 |
Runtime error |
1340 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |