Submission #1042282

# Submission time Handle Problem Language Result Execution time Memory
1042282 2024-08-02T19:14:44 Z Abito Sirni (COCI17_sirni) C++17
0 / 140
244 ms 786432 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
//#define int long long
#define ll long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=1e7+5;
int a[N],n;
set<int> ad[N],er[N],s;
bool b[N];
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i],b[a[i]]=1;
    for (int i=1;i<N;i++){
        if (!b[i]) continue;
        for (int j=i;j<N;j+=i){
            if (j!=i) ad[j].ep(j);
            if (j+i<N) er[j+i].ep(j);
        }
    }
    int ans=0;
    for (int i=1;i<N;i++){
        for (auto u:ad[i]) s.ep(u);
        if (b[i] && !s.empty()){
            //cout<<i<<endl;
            //for (auto u:s) cout<<u<<' ';cout<<endl;
            ans+=i-(*--s.end());
        }
        if (b[i]) s.ep(i);
        for (auto u:er[i]) s.erase(u);
    }
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 231 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 244 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 231 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 218 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 224 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 235 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 229 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 231 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 242 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 235 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -