# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
147706 |
2019-08-30T12:55:15 Z |
Ruxandra985 |
Sirni (COCI17_sirni) |
C++14 |
|
5000 ms |
786432 KB |
#include <cstdio>
#include <algorithm>
#define DIM 100010
using namespace std;
int v[DIM];
struct muchie {
int cost , x , y;
} m[30000000];
int tt[DIM];
int biggest[10000010];
int cmp (muchie a , muchie b){
if (a.cost != b.cost)
return a.cost<b.cost;
if (a.x != b.x)
return a.x<b.x;
return a.y < b.y;
}
int fth ( int x ){
int aux;
int init = x;
while (tt[x]>=0){
x = tt[x];
}
while (tt[init]>=0){
aux = tt[init];
tt[init] = x;
init = aux;
}
return x;
}
int main()
{
//freopen ("a.in" , "r" , stdin);
// freopen ("a.out" , "w" , stdout);
int n,i,elem,p,mch,j,x,y,tx,ty;
long long sol=0;
scanf ("%d",&n);
for (i=1;i<=n;i++){
scanf ("%d",&v[i]);
}
sort (v+1,v+n+1);
elem = 0;
for (i=1;i<=n;i++){
if (i==1 || v[i]!=v[i-1])
v[++elem] = v[i];
}
n = elem; /// MA IMPUSC NU POT SA CRED CA AM PUS ASTA DUPA FOR
p=n;
for (i=v[n];i;i--){
if (p && v[p] == i){
biggest[i] = p;
p--;
}
else biggest[i] = biggest[i+1];
}
mch=0;
for (i=1;i<=n;i++){
if (i!=n && v[i+1]/v[i] == 1){
mch++;
m[mch].cost = v[i+1] % v[i];
m[mch].x = i;
m[mch].y = i+1;
//printf ("%d %d %d\n",v[i],v[i+1],v[i+1] % v[i]);
}
for (j=2*v[i];j<=v[n];j+=v[i]){
/// cea mai mica val mai mare decat j
x = biggest[j];
if (j/v[i] == v[x]/v[i]){ /// add muchie
mch++;
m[mch].cost = v[x] % v[i];
m[mch].x = i;
m[mch].y = x;
//printf ("%d %d %d\n",v[i],v[x],v[x] % v[i]);
}
}
}
for (i=1;i<=n;i++)
tt[i] = -1;
sort (m+1,m + mch + 1 , cmp);
for (i=1;i<=mch;i++){
x = m[i].x;
y = m[i].y;
tx = fth(x);
ty = fth(y);
if (tx!=ty){
sol+=m[i].cost;
//printf ("%d ",m[i].cost);
if (tt[tx] < tt[ty]){
tt[tx]+=tt[ty];
tt[ty] = tx;
}
else {
tt[ty]+=tt[tx];
tt[tx] = ty;
}
}
}
printf ("%lld",sol);
return 0;
}
Compilation message
sirni.cpp: In function 'int main()':
sirni.cpp:38:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d",&n);
~~~~~~^~~~~~~~~
sirni.cpp:40:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d",&v[i]);
~~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
39544 KB |
Output is correct |
2 |
Correct |
171 ms |
41584 KB |
Output is correct |
3 |
Correct |
55 ms |
39548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
524 KB |
Output is correct |
2 |
Correct |
741 ms |
40384 KB |
Output is correct |
3 |
Correct |
60 ms |
39544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
39448 KB |
Output is correct |
2 |
Correct |
53 ms |
39376 KB |
Output is correct |
3 |
Correct |
54 ms |
39672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
272 ms |
16932 KB |
Output is correct |
2 |
Correct |
1029 ms |
50424 KB |
Output is correct |
3 |
Correct |
390 ms |
22136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
6008 KB |
Output is correct |
2 |
Correct |
531 ms |
29500 KB |
Output is correct |
3 |
Correct |
278 ms |
15216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
614 ms |
32044 KB |
Output is correct |
2 |
Correct |
1313 ms |
63196 KB |
Output is correct |
3 |
Correct |
360 ms |
20956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
5496 KB |
Output is correct |
2 |
Correct |
1225 ms |
60316 KB |
Output is correct |
3 |
Correct |
342 ms |
20124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
390 ms |
54568 KB |
Output is correct |
2 |
Execution timed out |
5076 ms |
308232 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
384 ms |
54308 KB |
Output is correct |
2 |
Runtime error |
2498 ms |
786432 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
41780 KB |
Output is correct |
2 |
Runtime error |
2265 ms |
786432 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |