This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define ui unsigned int
#define f first
#define s second
#define ins insert
#define pb push_back
#define mp make_pair
#define ln '\n'
#define int ll
#define pii pair<int , int>
#define INF LLONG_MAX
#define vv(a) vector<a>
#define pp(a, b) pair<a, b>
#define pq(a) priority_queue<a>
#define qq(a) queue<a>
#define ss(a) set<a>
#define mss(a) multiset<a>
#define mm(a, b) map<a, b>
#define mmm(a , b) multimap<a , b>
#define sz(x) (x).size()
#define all(x) (x).begin() , (x).end()
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void solve(){
int n;
cin >> n;
vv(int) a(n);
for(int i=0 ; i<n ; i++){
cin >> a[i];
}
if(n == 1){
cout << 0 << ln;
return;
}
vector<int> now;
now.pb(0);
int minq = 1e9 , ind = -1;
for(int i=1 ; i<n ; i++){
if(minq > min(a[i]%a[0] , a[0]%a[i])){
minq = min(a[i]%a[0] , a[0]%a[i]);
ind = i;
}
}
now.pb(ind);
int ans = minq;
for(int i=2 ; i<n ; i++){
minq = 1e9;
for(int j=0 ; j<now.size() ; j++){
if(minq > min(a[i]%a[now[j]] , a[now[j]]%a[i])){
minq = min(a[i]%a[now[j]] , a[now[j]]%a[i]);
}
}
now.pb(i);
ans += minq;
}
cout << ans;
}
signed main(){
fastio
int t = 1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
Compilation message (stderr)
sirni.cpp: In function 'void solve()':
sirni.cpp:63:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int j=0 ; j<now.size() ; j++){
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |