# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
482398 | 2021-10-24T11:50:52 Z | MilosMilutinovic | Sirni (COCI17_sirni) | C++14 | 1207 ms | 786436 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,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) { for (int j=a[i];j<=a[n-1];j+=a[i]) { int x=id[j+(j==a[i])]; ed.pb({i,x,a[x]%a[i]}); } } 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 42 ms | 42688 KB | Output is correct |
2 | Correct | 222 ms | 90600 KB | Output is correct |
3 | Correct | 45 ms | 43208 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 40 ms | 39616 KB | Output is correct |
2 | Runtime error | 932 ms | 786436 KB | Execution killed with signal 9 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 42 ms | 42948 KB | Output is correct |
2 | Correct | 46 ms | 40628 KB | Output is correct |
3 | Correct | 42 ms | 43004 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 142 ms | 66276 KB | Output is correct |
2 | Correct | 348 ms | 90920 KB | Output is correct |
3 | Correct | 201 ms | 90848 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 57 ms | 43704 KB | Output is correct |
2 | Correct | 253 ms | 90576 KB | Output is correct |
3 | Correct | 156 ms | 65712 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 239 ms | 90920 KB | Output is correct |
2 | Correct | 454 ms | 140104 KB | Output is correct |
3 | Correct | 175 ms | 66348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 71 ms | 46336 KB | Output is correct |
2 | Correct | 534 ms | 140048 KB | Output is correct |
3 | Correct | 182 ms | 66224 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 196 ms | 75144 KB | Output is correct |
2 | Runtime error | 895 ms | 786436 KB | Execution killed with signal 9 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 211 ms | 75180 KB | Output is correct |
2 | Runtime error | 979 ms | 786436 KB | Execution killed with signal 9 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 68 ms | 52620 KB | Output is correct |
2 | Runtime error | 1207 ms | 786436 KB | Execution killed with signal 9 |
3 | Halted | 0 ms | 0 KB | - |