# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
147711 | 2019-08-30T13:12:52 Z | Ruxandra985 | Sirni (COCI17_sirni) | C++14 | 5000 ms | 412712 KB |
/// alta mini bulaneala :) #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 && v[i+1] % v[i]<=50000){ 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] && v[x] % v[i]<=50000){ /// 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 39416 KB | Output is correct |
2 | Correct | 165 ms | 41524 KB | Output is correct |
3 | Correct | 55 ms | 39548 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 704 ms | 40340 KB | Output is correct |
3 | Correct | 55 ms | 39544 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 54 ms | 39628 KB | Output is correct |
2 | Correct | 53 ms | 39420 KB | Output is correct |
3 | Correct | 54 ms | 39544 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 202 ms | 16924 KB | Output is correct |
2 | Correct | 742 ms | 50448 KB | Output is correct |
3 | Correct | 284 ms | 22188 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 6008 KB | Output is correct |
2 | Correct | 383 ms | 29640 KB | Output is correct |
3 | Correct | 206 ms | 15324 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 440 ms | 31992 KB | Output is correct |
2 | Correct | 918 ms | 63240 KB | Output is correct |
3 | Correct | 259 ms | 20856 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 68 ms | 5624 KB | Output is correct |
2 | Correct | 872 ms | 60408 KB | Output is correct |
3 | Correct | 249 ms | 20088 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 316 ms | 54464 KB | Output is correct |
2 | Execution timed out | 5096 ms | 308296 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 305 ms | 54244 KB | Output is correct |
2 | Execution timed out | 5078 ms | 412712 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 92 ms | 41792 KB | Output is correct |
2 | Execution timed out | 5093 ms | 411016 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |