# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
147704 |
2019-08-30T12:49:27 Z |
Ruxandra985 |
Sirni (COCI17_sirni) |
C++14 |
|
1956 ms |
318208 KB |
#include <cstdio>
#include <algorithm>
#define DIM 100010
using namespace std;
int v[DIM];
struct muchie {
int cost , x , y;
} m[10000000];
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 |
167 ms |
41532 KB |
Output is correct |
3 |
Correct |
55 ms |
39416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
702 ms |
40272 KB |
Output is correct |
3 |
Correct |
57 ms |
39544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
39580 KB |
Output is correct |
2 |
Correct |
53 ms |
39484 KB |
Output is correct |
3 |
Correct |
55 ms |
39624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
274 ms |
16936 KB |
Output is correct |
2 |
Correct |
1027 ms |
50360 KB |
Output is correct |
3 |
Correct |
391 ms |
22192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
6008 KB |
Output is correct |
2 |
Correct |
514 ms |
29544 KB |
Output is correct |
3 |
Correct |
270 ms |
15172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
618 ms |
31992 KB |
Output is correct |
2 |
Correct |
1317 ms |
63212 KB |
Output is correct |
3 |
Correct |
363 ms |
20916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
5496 KB |
Output is correct |
2 |
Correct |
1220 ms |
60280 KB |
Output is correct |
3 |
Correct |
348 ms |
20088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
396 ms |
54480 KB |
Output is correct |
2 |
Runtime error |
1956 ms |
318188 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 |
383 ms |
54380 KB |
Output is correct |
2 |
Runtime error |
1770 ms |
318208 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 |
41848 KB |
Output is correct |
2 |
Runtime error |
1179 ms |
318124 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |