# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
937695 | 2024-03-04T11:16:54 Z | PieArmy | Sirni (COCI17_sirni) | C++17 | 2696 ms | 435380 KB |
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 merhaba{ int cos,a,b; }; 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; } }; 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<merhaba>pq; 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]){ merhaba x; x.cos=v[nex[j+1]]-j; x.a=i; x.b=nex[j+1]; pq.pb(x); } continue; } if(v[nex[j]]<j+v[i]){ merhaba x; x.cos=v[nex[j]]-j; x.a=i; x.b=nex[j]; pq.pb(x); } } } sort(pq.begin(),pq.end(),[&](const merhaba &x,const merhaba &y){return x.cos<y.cos;}); ll ans=0; DSU dsu(n); for(merhaba x:pq){ int cos=x.cos,a=x.a,b=x.b; 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; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 39516 KB | Output is correct |
2 | Correct | 59 ms | 42556 KB | Output is correct |
3 | Correct | 17 ms | 39708 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 604 KB | Output is correct |
2 | Correct | 291 ms | 40648 KB | Output is correct |
3 | Correct | 18 ms | 39768 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 39772 KB | Output is correct |
2 | Correct | 17 ms | 39924 KB | Output is correct |
3 | Correct | 17 ms | 39772 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 70 ms | 18756 KB | Output is correct |
2 | Correct | 213 ms | 57144 KB | Output is correct |
3 | Correct | 91 ms | 31036 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 8448 KB | Output is correct |
2 | Correct | 157 ms | 55520 KB | Output is correct |
3 | Correct | 62 ms | 16456 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 134 ms | 57240 KB | Output is correct |
2 | Correct | 275 ms | 105760 KB | Output is correct |
3 | Correct | 89 ms | 31548 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 9296 KB | Output is correct |
2 | Correct | 288 ms | 105508 KB | Output is correct |
3 | Correct | 84 ms | 31856 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 122 ms | 66624 KB | Output is correct |
2 | Correct | 1757 ms | 435380 KB | Output is correct |
3 | Correct | 138 ms | 66880 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 120 ms | 67392 KB | Output is correct |
2 | Correct | 2634 ms | 435180 KB | Output is correct |
3 | Correct | 178 ms | 67644 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 44036 KB | Output is correct |
2 | Correct | 2696 ms | 435196 KB | Output is correct |
3 | Correct | 92 ms | 31552 KB | Output is correct |