# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
147708 | 2019-08-30T13:04:43 Z | Ruxandra985 | Sirni (COCI17_sirni) | C++14 | 5000 ms | 412656 KB |
#include <cstdio> #include <algorithm> #define DIM 100010 using namespace std; int v[DIM]; pair <int,pair <int,int> > m[40000000]; int tt[DIM]; int biggest[10000010]; 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; 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].first = v[i+1] % v[i]; m[mch].second.first = i; m[mch].second.second = i+1; } 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].first = v[x] % v[i]; m[mch].second.first = i; m[mch].second.second = x; } } } for (i=1;i<=n;i++) tt[i] = -1; sort (m+1,m + mch + 1); int pus = 0; for (i=1;i<=mch && pus!=n-1;i++){ x = m[i].second.first; y = m[i].second.second; tx = fth(x); ty = fth(y); if (tx!=ty){ sol+=m[i].first; pus++; //printf ("%d ",m[i].first); 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 39416 KB | Output is correct |
2 | Correct | 159 ms | 41760 KB | Output is correct |
3 | Correct | 61 ms | 39416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 718 ms | 40336 KB | Output is correct |
3 | Correct | 56 ms | 39672 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 57 ms | 39576 KB | Output is correct |
2 | Correct | 53 ms | 39324 KB | Output is correct |
3 | Correct | 54 ms | 39544 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 203 ms | 17016 KB | Output is correct |
2 | Correct | 738 ms | 50424 KB | Output is correct |
3 | Correct | 284 ms | 22136 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 6008 KB | Output is correct |
2 | Correct | 383 ms | 29536 KB | Output is correct |
3 | Correct | 198 ms | 15328 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 473 ms | 32072 KB | Output is correct |
2 | Correct | 930 ms | 63160 KB | Output is correct |
3 | Correct | 260 ms | 20988 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 68 ms | 5496 KB | Output is correct |
2 | Correct | 869 ms | 60296 KB | Output is correct |
3 | Correct | 249 ms | 20216 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 322 ms | 54456 KB | Output is correct |
2 | Execution timed out | 5068 ms | 308132 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 306 ms | 54228 KB | Output is correct |
2 | Execution timed out | 5109 ms | 412656 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 89 ms | 41720 KB | Output is correct |
2 | Execution timed out | 5129 ms | 410960 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |