# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
147709 | 2019-08-30T13:07:43 Z | Ruxandra985 | Sirni (COCI17_sirni) | C++14 | 5000 ms | 275092 KB |
/// mini bulaneala :) #include <cstdio> #include <algorithm> #define DIM 100010 using namespace std; int v[DIM]; pair <int,pair <int,int> > m[20000010]; 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; /// 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 && mch < 20000000;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] && mch<20000000 ;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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 54 ms | 39544 KB | Output is correct |
2 | Correct | 165 ms | 41592 KB | Output is correct |
3 | Correct | 55 ms | 39416 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 504 KB | Output is correct |
2 | Correct | 896 ms | 40324 KB | Output is correct |
3 | Correct | 57 ms | 39544 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 39544 KB | Output is correct |
2 | Correct | 53 ms | 39416 KB | Output is correct |
3 | Correct | 54 ms | 39544 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 216 ms | 16844 KB | Output is correct |
2 | Correct | 741 ms | 50356 KB | Output is correct |
3 | Correct | 289 ms | 22188 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 6008 KB | Output is correct |
2 | Correct | 411 ms | 29532 KB | Output is correct |
3 | Correct | 217 ms | 15216 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 443 ms | 32092 KB | Output is correct |
2 | Correct | 935 ms | 63136 KB | Output is correct |
3 | Correct | 268 ms | 20856 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 71 ms | 5496 KB | Output is correct |
2 | Correct | 881 ms | 60292 KB | Output is correct |
3 | Correct | 252 ms | 20088 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 315 ms | 54392 KB | Output is correct |
2 | Incorrect | 4945 ms | 275092 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 309 ms | 54416 KB | Output is correct |
2 | Execution timed out | 5097 ms | 275004 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 90 ms | 41860 KB | Output is correct |
2 | Incorrect | 4906 ms | 275032 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |