# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
555325 |
2022-04-30T12:53:46 Z |
stefantaga |
Sirni (COCI17_sirni) |
C++14 |
|
729 ms |
297896 KB |
#include <bits/stdc++.h>
using namespace std;
int fr[10000005],n,x,i,tata[1000005],rang[1000005];
set <pair <int,int>> m;
vector <pair <int,int>> bonjour[10000005];
int costul(int a,int b)
{
return min (a%b,b%a);
}
int parinte (int x)
{
if (x!=tata[x])
{
return tata[x]=parinte(tata[x]);
}
return x;
}
void uneste(int x,int y)
{
x=parinte(x);
y=parinte(y);
if (rang[x]<rang[y])
{
tata[x]=y;
}
else
if (rang[y]<rang[x])
{
tata[y]=x;
}
else
{
tata[x]=y;
rang[y]++;
}
}
int v[100005],q,maxim;
int main()
{
ios_base :: sync_with_stdio(false);
cin.tie(0);
#ifdef HOME
ifstream cin("date.in");
ofstream cout("date.out");
#endif // HOME
cin>>n;
for (i=1;i<=n;i++)
{
cin>>x;
if (fr[x]==0)
{
fr[x]=1;
v[++q]=x;
}
maxim=max(maxim,x);
}
n=q;
for (i=1;i<=n;i++)
{
m.insert({v[i],i});
}
for (i=1;i<=n;i++)
{
for (int j=1;j*v[i]<=maxim;j++)
{
auto ceau = m.lower_bound({j*v[i],1});
if (ceau == m.end())
{
break;
}
pair <int,int> Locas = (*ceau);
bonjour[costul(Locas.first,v[i])].push_back({i,Locas.second});
}
}
for (i=1;i<=n;i++)
{
tata[i]=i;
rang[i]=1;
}
long long sum=0;
for (i=0;i<=maxim;i++)
{
for (int j=0;j<bonjour[i].size();j++)
{
int x = bonjour[i][j].first;
int y =bonjour[i][j].second;
if (parinte(x)!=parinte(y))
{
sum=sum+i;
uneste(x,y);
}
}
}
cout<<sum;
return 0;
}
Compilation message
sirni.cpp: In function 'int main()':
sirni.cpp:84:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for (int j=0;j<bonjour[i].size();j++)
| ~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
125 ms |
238924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
109 ms |
235372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
127 ms |
239140 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
377 ms |
255780 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
142 ms |
241848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
729 ms |
267260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
184 ms |
242112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
503 ms |
294632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
521 ms |
297896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
198 ms |
272752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |