# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1117286 |
2024-11-23T08:18:41 Z |
hihihihaw |
Sirni (COCI17_sirni) |
C++17 |
|
4999 ms |
517144 KB |
#pragma GCC optimize("O3,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pb push_back
#define pii pair<int, int>
#define sz(v) (int)v.size()
#define fi first
#define se second
#define INF 999999992000000023
#define MOD 1000000007
#define cint(x) int x;cin >> x;
#define cinarr(a, n) int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
#define coutarr(a) for (auto d : a){cout << d << " ";} cout << endl;
#define coutarrD(a) for (auto d : a) {cout << d.fi << "," << d.se << " "; }cout << endl;
#define BERKAY_TUP ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define ld long double
#define mid (start + end) / 2
#define vvi vector<vector<int>>
int t=1;
int interactive=0;
int usaco=0;
int testCase=0;
int a[10000023]={};
int pre[10000023];
int parent[10000023];
int find(int x){
if (parent[x]==x) return x;
return parent[x]=find(parent[x]);
}
void unionSet(int x,int y){
x=find(x),y=find(y);
if (x==y) return;
parent[x]=y;
}
void solve(){
int n;
cin>>n;
set<int> s;
for (int i=0;i<n;i++){
int x;
cin>>x;
s.insert(x);
}
for (auto d:s) a[d]=d;
int x=0;
for (int i=10000022;i>=0;i--){
parent[i]=i;
if (a[i]!=0) x=a[i];
pre[i]=x;
}
vector<pair<int,pii>> v;
for (int i=1;i<10000023;i++){
if (a[i]==0) continue;
for (int j=i;j<10000023;j+=i){
int z;
if (j==i) z=pre[j+1];
else z=pre[j];
//if (i==2 && j<20) cout<<z<<" "<<j<<endl;
if (z/i==j/i && z!=0){
v.pb({z%i,{i,z}});
}
}
}
sort(v.begin(),v.end());
int ans=0;
for (auto d:v){
int x,y,c;
x=d.se.fi,y=d.se.se,c=d.fi;
if (find(x)!=find(y)){
ans+=c;
unionSet(x,y);
}
}
cout<<ans<<endl;
}
int32_t main(){
BERKAY_TUP;
if (usaco)
{
freopen("help.in", "r", stdin);
freopen("help.out", "w", stdout);
}
if (!interactive)
{
#ifdef Local
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
// freopen("wormsort.out", "w", stdout);
#endif
}
if (t == 1)
solve();
else
{
cin >> t;
while (t--)
{
testCase++;
solve();
}
}
return 0;
}
Compilation message
sirni.cpp: In function 'int32_t main()':
sirni.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
89 | freopen("help.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sirni.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | freopen("help.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
84296 KB |
Output is correct |
2 |
Correct |
114 ms |
85748 KB |
Output is correct |
3 |
Correct |
75 ms |
86356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
80712 KB |
Output is correct |
2 |
Correct |
308 ms |
84044 KB |
Output is correct |
3 |
Correct |
73 ms |
86344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
86344 KB |
Output is correct |
2 |
Correct |
72 ms |
85156 KB |
Output is correct |
3 |
Correct |
77 ms |
86344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
314 ms |
100192 KB |
Output is correct |
2 |
Correct |
865 ms |
136844 KB |
Output is correct |
3 |
Correct |
386 ms |
111512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
86716 KB |
Output is correct |
2 |
Correct |
466 ms |
132976 KB |
Output is correct |
3 |
Correct |
334 ms |
97204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
551 ms |
136532 KB |
Output is correct |
2 |
Correct |
1140 ms |
185660 KB |
Output is correct |
3 |
Correct |
388 ms |
111740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
88512 KB |
Output is correct |
2 |
Correct |
1065 ms |
184736 KB |
Output is correct |
3 |
Correct |
383 ms |
111764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
325 ms |
147620 KB |
Output is correct |
2 |
Correct |
3841 ms |
517144 KB |
Output is correct |
3 |
Correct |
341 ms |
147888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
305 ms |
147124 KB |
Output is correct |
2 |
Correct |
4999 ms |
515256 KB |
Output is correct |
3 |
Correct |
419 ms |
147760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
117436 KB |
Output is correct |
2 |
Correct |
4917 ms |
508440 KB |
Output is correct |
3 |
Correct |
415 ms |
112020 KB |
Output is correct |