# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1004480 |
2024-06-21T09:20:09 Z |
Huseyn123 |
Sirni (COCI17_sirni) |
C++17 |
|
1197 ms |
786432 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define int ll
#define MAX 100001
#define INF INT_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define outputar(a,b){\
for(int i=0;i<b;i++){\
cout << a[i] << " ";\
}\
cout << endl;\
}
#define outputvec(a){\
for(auto x:a){\
cout << (int)x << " ";\
}\
cout << endl;\
}
#define reset(a,n,v){\
for(int i=0;i<n;i++){\
a[i]=v;\
}\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
inline void USACO(string filename){
freopen((filename+".in").c_str(),"r",stdin);
freopen((filename+".out").c_str(),"w",stdout);
}
int n,q,t=1,m,k,x,y,z,x2,y2,z2;
vector<int> a;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string s[MAX],str[MAX];
//int e[1001][1001];
string s1,s2,s3;
const int mod = 998244353;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
struct DSU{
vector<int> e;
DSU(int N){ e=vector<int>(N+1,-1);}
int get(int x){return e[x]<0 ? x : e[x]=get(e[x]);}
bool same_set(int x,int y){ return get(x)==get(y);}
int size(int x){return -e[get(x)];}
bool unite(int x,int y){
x=get(x);
y=get(y);
if(x==y) return false;
if(e[x]>e[y]) swap(x,y);
e[x]+=e[y]; e[y]=x;
return true;
}
};
void solve(){
cin >> n;
a.clear();
a.resize(n);
for(int i=0;i<n;i++){
cin >> a[i];
}
int mx=0;
sortv(a);
a.erase(unique(all(a)),a.end());
n=(int)a.size();
mx=a[n-1];
vector<array<int,3>> edges;
for(int i=0;i<n;i++){
for(int j=a[i];j<=mx;j+=a[i]){
auto it=lb(a,j);
if(it-a.begin()==i){
++it;
}
if(it!=a.end()){
edges.pb({*it-j,it-a.begin(),i});
}
}
}
DSU dsu(n);
sortv(edges);
int res=0;
for(auto x:edges){
if(dsu.unite(x[1],x[2])){
res+=x[0];
}
}
cout << res << "\n";
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input13.txt","r",stdin);
//cin >> t;
ll cnt1=1;
while(t--){
solve();
cnt1++;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7000 KB |
Output is correct |
2 |
Correct |
439 ms |
105296 KB |
Output is correct |
3 |
Correct |
6 ms |
7512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7004 KB |
Output is correct |
2 |
Runtime error |
666 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7004 KB |
Output is correct |
2 |
Correct |
4 ms |
6904 KB |
Output is correct |
3 |
Correct |
4 ms |
7196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
245 ms |
57288 KB |
Output is correct |
2 |
Correct |
950 ms |
106736 KB |
Output is correct |
3 |
Correct |
487 ms |
106616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
13124 KB |
Output is correct |
2 |
Correct |
411 ms |
106580 KB |
Output is correct |
3 |
Correct |
238 ms |
57132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
504 ms |
106584 KB |
Output is correct |
2 |
Correct |
1197 ms |
204976 KB |
Output is correct |
3 |
Correct |
363 ms |
57268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
19648 KB |
Output is correct |
2 |
Correct |
1181 ms |
205040 KB |
Output is correct |
3 |
Correct |
362 ms |
57292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
261 ms |
57480 KB |
Output is correct |
2 |
Runtime error |
717 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
334 ms |
57616 KB |
Output is correct |
2 |
Runtime error |
669 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
13160 KB |
Output is correct |
2 |
Runtime error |
970 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |