# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
935853 | 2024-02-29T17:21:48 Z | PieArmy | Sirni (COCI17_sirni) | C++17 | 5000 ms | 786432 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 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; } } priority_queue<vector<int>>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]) pq.push({j-v[nex[j+1]],i,nex[j+1]}); continue; } if(v[nex[j]]<j+v[i]) pq.push({j-v[nex[j]],i,nex[j]}); } } ll ans=0; DSU dsu(n); while(pq.size()){ int cos=-pq.top()[0],a=pq.top()[1],b=pq.top()[2]; pq.pop(); 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 | 20 ms | 39768 KB | Output is correct |
2 | Correct | 124 ms | 51200 KB | Output is correct |
3 | Correct | 19 ms | 40088 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1112 KB | Output is correct |
2 | Correct | 341 ms | 42896 KB | Output is correct |
3 | Correct | 20 ms | 40088 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 39760 KB | Output is correct |
2 | Correct | 15 ms | 39516 KB | Output is correct |
3 | Correct | 18 ms | 39956 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 761 ms | 62028 KB | Output is correct |
2 | Correct | 3514 ms | 219876 KB | Output is correct |
3 | Correct | 1144 ms | 89132 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 55 ms | 15368 KB | Output is correct |
2 | Correct | 2419 ms | 170752 KB | Output is correct |
3 | Correct | 710 ms | 61320 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1989 ms | 170792 KB | Output is correct |
2 | Correct | 4748 ms | 334104 KB | Output is correct |
3 | Correct | 984 ms | 89524 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 151 ms | 22912 KB | Output is correct |
2 | Execution timed out | 5024 ms | 333860 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1288 ms | 125120 KB | Output is correct |
2 | Runtime error | 1234 ms | 786432 KB | Execution killed with signal 9 |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1322 ms | 124244 KB | Output is correct |
2 | Runtime error | 1327 ms | 786432 KB | Execution killed with signal 9 |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 127 ms | 51972 KB | Output is correct |
2 | Runtime error | 1750 ms | 786432 KB | Execution killed with signal 9 |
3 | Halted | 0 ms | 0 KB | - |