# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
935925 | noyancanturk | Sirni (COCI17_sirni) | C++17 | 2622 ms | 437004 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
typedef long long ll;
ll pie(ll army){return (1ll<<army);}
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define endl '\n';
#define mid ((left+right)>>1)
const ll inf=2000000000000000005;
const int sonsuz=2000000005;
using namespace std;
ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;}
struct DSU{
int n;
vector<int>par,siz;
DSU(int N){
n=N;
par.resize(n);iota(par.begin(),par.end(),0);
siz.resize(n,1);
}
int get(int x){
if(par[x]==x)return x;
return par[x]=get(par[x]);
}
bool unite(int x,int y){
x=get(x);y=get(y);
if(x==y)return false;
if(siz[x]<siz[y])swap(x,y);
par[y]=x;
siz[x]+=siz[y];
return true;
}
};
struct edge{
int w,x,y;
};
void code(){
int n;cin>>n;
int arr[n];for(int &x:arr)cin>>x;
sort(arr,arr+n);
int mx=arr[n-1];
vector<int>v;
int las=-1;
for(int i=0;i<n;i++){
if(arr[i]!=las)v.pb(arr[i]);
las=arr[i];
}
n=v.size();
vector<int>nex(mx+2);
int pos=n-1;
for(int i=mx+1;i>=0;i--){
nex[i]=pos;
if(pos&&(i==v[pos-1])){
pos--;
nex[i]=pos;
}
}
vector<edge>pp;
for(int i=0;i<n;i++){
for(int j=v[i];j<=mx;j+=v[i]){
if(nex[j]==i){
if(v[nex[j+1]]<j+v[i])
pp.pb({v[nex[j+1]]-j,i,nex[j+1]});
continue;
}
if(v[nex[j]]<j+v[i])
pp.pb({v[nex[j]]-j,i,nex[j]});
}
}
sort(pp.data(),pp.data()+pp.size(),[&](edge&e1,edge&e2)-> bool {
return e1.w<e2.w;
});
ll ans=0;
DSU dsu(n);
for(auto [cos,a,b]:pp){
if(dsu.unite(a,b))
ans+=cos;
}
cout<<ans;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
int t=1;
if(!t)cin>>t;
while(t--){code();cout<<endl;}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |