# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
779890 |
2023-07-12T02:07:25 Z |
vjudge1 |
Sirni (COCI17_sirni) |
C++17 |
|
1029 ms |
502944 KB |
#include<bits/stdc++.h>
using namespace std;
#define task "CC"
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define bit(n,i) ((n>>i)&1)
#define all(x) x.begin(),x.end()
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,bmi,bmi2,sse,sse2,sse3,ssse3,sse4,popcnt")
//#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef double ld;
typedef pair<ld,ld> pdd;
typedef pair<ll,ll> pll;
const ll maxn=1e7+1;
const ll N=1e5+2;
int n,nxt[maxn+1],par[N],x[N];
bool ct[N];
vector<pii> Edge[maxn];
int Find(int v) {
return (par[v] < 0) ?v: (par[v] = Find(par[v]));
}
bool Union(int x, int y) {
if ((x = Find(x)) == (y = Find(y)))
{
return false ;
}
if (par[y] < par[x])
{
swap(x, y);
}
par[x] += par[y];
par[y] = x;
return true;
}
void sol()
{
cin >> n;
for (int i=1;i<=n;i++)
{
cin >> x[i];
par[i]=-1;
}
sort(x+1,x+1+n);
for1(i,1,n)
{
if (nxt[x[i]]==0) nxt[x[i]]=i;
}
int ans=0;
nxt[(int)x[n]+1]=-1;
for2(i,x[n],1)
{
if (nxt[i]==0) nxt[i]=nxt[i+1];
//cerr<< i<< ' '<<nxt[i]<<'\n';
}
// for (int i=1;i<=x[n];i++)
// {
// //cerr<<"wtf\n";
// if (nxt[i]==i)
// {
// if (nxt[i+1]==-1) continue;
// Edge[nxt[i+1]-i].pb({nxt[i+1],i});
// for (int j=2*i;j<=x[n];j+=i)
// {
// if (nxt[j]==-1) break;
// Edge[nxt[j]-j].pb({nxt[j],i});
// }
// }
// }
for1(k,1,n)
{
if (x[k]==x[k-1]) continue;
int i=x[k];
if (nxt[i+1]==-1) continue;
Edge[x[nxt[i+1]]-i].pb({nxt[i+1],k});
if (ct[k]) continue;
for (int j=2*i;j<=x[n];j+=i)
{
if (nxt[j]==-1) break;
Edge[x[nxt[j]]-j].pb({nxt[j],k});
if (x[nxt[j]]==j) ct[nxt[j]]=1;
}
}
for (int i=0;i<=x[n];i++)
{
for (auto x:Edge[i])
{
//cerr<<i<<' '<<x.se<<' '<<x.fi<<'\n';
if (!Union(x.fi,x.se)) continue;
ans+=i;
}
Edge[i].clear();
}
cout << ans;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
sol();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
169 ms |
274380 KB |
Output is correct |
2 |
Correct |
334 ms |
306840 KB |
Output is correct |
3 |
Correct |
189 ms |
274584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
235160 KB |
Output is correct |
2 |
Correct |
1029 ms |
502944 KB |
Output is correct |
3 |
Correct |
170 ms |
275336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
157 ms |
274440 KB |
Output is correct |
2 |
Correct |
170 ms |
274268 KB |
Output is correct |
3 |
Correct |
168 ms |
274432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
141 ms |
247048 KB |
Output is correct |
2 |
Correct |
157 ms |
255932 KB |
Output is correct |
3 |
Correct |
148 ms |
258576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
241100 KB |
Output is correct |
2 |
Correct |
145 ms |
253216 KB |
Output is correct |
3 |
Correct |
127 ms |
244764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
252228 KB |
Output is correct |
2 |
Correct |
162 ms |
259164 KB |
Output is correct |
3 |
Correct |
141 ms |
252132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
238604 KB |
Output is correct |
2 |
Correct |
158 ms |
259724 KB |
Output is correct |
3 |
Correct |
146 ms |
258268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
223 ms |
288020 KB |
Output is correct |
2 |
Correct |
554 ms |
418660 KB |
Output is correct |
3 |
Correct |
230 ms |
290900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
234 ms |
291808 KB |
Output is correct |
2 |
Correct |
718 ms |
465336 KB |
Output is correct |
3 |
Correct |
360 ms |
345172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
276676 KB |
Output is correct |
2 |
Correct |
716 ms |
432184 KB |
Output is correct |
3 |
Correct |
163 ms |
257600 KB |
Output is correct |