# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
484136 | 2021-11-02T07:28:56 Z | MilosMilutinovic | Sirni (COCI17_sirni) | C++14 | 3046 ms | 576520 KB |
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef long long ll; typedef pair<int,int> PII; typedef double db; mt19937 mrand(random_device{}()); const ll mod=1000000007; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head const int N=101000; int n,_[N],a[N],id[10000005],f[N]; int find(int x){ return f[x]==x?x:f[x]=find(f[x]); } struct edge{ int u,v; ll w; bool operator<(const edge oth) const{return w<oth.w;} }; vector<edge> ed; bool x[10000005]; int main() { scanf("%d",&n); rep(i,0,n) f[i]=i; rep(i,0,n) scanf("%d",_+i),x[_[i]]=true; sort(_,_+n); int nxt=0; rep(i,0,n) if (i==0||_[i]!=_[i-1]) a[nxt++]=_[i]; n=nxt; int pos=n-1; id[10000002]=0; per(i,1,10000002) { if (x[i]) id[i]=pos,pos--; else id[i]=id[i+1]; } rep(i,0,n) { int lst=-1; for (int j=a[i];j<10000002;j+=a[i]) { int x=id[j+(j==a[i]?1:0)]; if (lst!=x) ed.pb({i,x,a[x]%a[i]}),lst=x; } } sort(all(ed)); ll ans=0; for (auto e:ed) { int x=find(e.u); int y=find(e.v); if (x!=y) { ans+=e.w; f[x]=y; } } printf("%lld",ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 42820 KB | Output is correct |
2 | Correct | 91 ms | 45404 KB | Output is correct |
3 | Correct | 44 ms | 43104 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 98 ms | 39724 KB | Output is correct |
2 | Correct | 325 ms | 41124 KB | Output is correct |
3 | Correct | 44 ms | 43044 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 43076 KB | Output is correct |
2 | Correct | 42 ms | 40584 KB | Output is correct |
3 | Correct | 43 ms | 42948 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 247 ms | 74500 KB | Output is correct |
2 | Correct | 664 ms | 107816 KB | Output is correct |
3 | Correct | 281 ms | 75104 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 72 ms | 44848 KB | Output is correct |
2 | Correct | 478 ms | 106972 KB | Output is correct |
3 | Correct | 311 ms | 73944 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 449 ms | 107344 KB | Output is correct |
2 | Correct | 817 ms | 173692 KB | Output is correct |
3 | Correct | 266 ms | 75192 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 218 ms | 48360 KB | Output is correct |
2 | Correct | 1062 ms | 173452 KB | Output is correct |
3 | Correct | 283 ms | 75124 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 187 ms | 83256 KB | Output is correct |
2 | Correct | 2093 ms | 576520 KB | Output is correct |
3 | Correct | 201 ms | 84124 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 180 ms | 83272 KB | Output is correct |
2 | Correct | 3004 ms | 576328 KB | Output is correct |
3 | Correct | 231 ms | 84120 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 66 ms | 53584 KB | Output is correct |
2 | Correct | 3046 ms | 576360 KB | Output is correct |
3 | Correct | 293 ms | 75256 KB | Output is correct |