# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
171906 | 2019-12-30T15:23:11 Z | rzbt | Sirni (COCI17_sirni) | C++14 | 5000 ms | 449152 KB |
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define F first #define S second #define all(x) x.begin(),x.end() #define MAXN 100005 #define MAXB 10000007 typedef long long ll; using namespace std; int n; int niz[MAXN]; set< pair<int,int> > s; vector<pair<int,int> > grane[MAXB]; int cale[MAXN],vel[MAXN]; int koren(int p){ while(p!=cale[p]){ cale[p]=cale[cale[p]]; p=cale[p]; } return p; } ll res=0; void spoji(int a,int b,int c){ a=koren(a); b=koren(b); if(a==b)return; res+=c; if(vel[a]<vel[b])swap(a,b); cale[b]=a; vel[a]+=vel[b]; } int main() { for(int i=0;i<MAXN;i++){ cale[i]=i; vel[i]=1; } scanf("%d", &n); for(int i=1;i<=n;i++){ scanf("%d",niz+i); } sort(niz+1,niz+n+1); for(int i=1;i<=n;i++) s.insert(mp(niz[i],i)); for(int i=1;i<=n;i++){ if(niz[i]==niz[i+1]){ grane[0].pb(mp(i,i+1)); continue; } for(int j=niz[i];j<MAXB;j+=niz[i]){ auto a=s.lower_bound(mp(j+(j==niz[i]?1:0),0)); if(a==s.end())break; while(j+niz[i]<=a->F)j+=niz[i]; grane[a->F-j].pb(mp(i,a->second)); } } for(int i=0;i<MAXB;i++){ for(auto x:grane[i]){ spoji(x.F,x.S,i); } } printf("%lld",res); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 249 ms | 236152 KB | Output is correct |
2 | Correct | 267 ms | 238328 KB | Output is correct |
3 | Correct | 247 ms | 236204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 244 ms | 236024 KB | Output is correct |
2 | Correct | 282 ms | 236784 KB | Output is correct |
3 | Correct | 247 ms | 236176 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 245 ms | 236256 KB | Output is correct |
2 | Correct | 246 ms | 236024 KB | Output is correct |
3 | Correct | 246 ms | 236280 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 669 ms | 251264 KB | Output is correct |
2 | Correct | 1388 ms | 277976 KB | Output is correct |
3 | Correct | 705 ms | 256488 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 276 ms | 238340 KB | Output is correct |
2 | Correct | 867 ms | 264260 KB | Output is correct |
3 | Correct | 623 ms | 252032 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1096 ms | 263512 KB | Output is correct |
2 | Correct | 1781 ms | 292812 KB | Output is correct |
3 | Correct | 727 ms | 254724 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 361 ms | 241488 KB | Output is correct |
2 | Correct | 1692 ms | 287748 KB | Output is correct |
3 | Correct | 679 ms | 254744 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 674 ms | 253728 KB | Output is correct |
2 | Execution timed out | 5114 ms | 449152 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 704 ms | 253672 KB | Output is correct |
2 | Execution timed out | 5033 ms | 431676 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 295 ms | 239348 KB | Output is correct |
2 | Execution timed out | 5050 ms | 426024 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |