Submission #136374

# Submission time Handle Problem Language Result Execution time Memory
136374 2019-07-25T07:58:43 Z darkkcyan Sirni (COCI17_sirni) C++14
0 / 140
487 ms 67220 KB
#include <bits/stdc++.h>
using namespace std;
using namespace std::placeholders;

// #define rand __rand
// mt19937 rand(chrono::system_clock::now().time_since_epoch().count());  // or mt19937_64
#define llong long long 
#define xx first
#define yy second
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )
#define all(x) x.begin(), x.end()

template<class T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define maxn 101010
int n;
int a[maxn];
int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    rep(i, n) cin >> a[i];
    sort(a, a + n);
    
    n = (int)(unique(a, a + n) - a);

    min_priority_queue<tuple<int, int, int*>> pq;
    rep(i, n) {
        for (int k = 1; k * a[i] <= a[n - 1]; ++k) {
            auto t = lower_bound(a, a + n, k * a[i]);
            if (t == a + n or *t / a[i] != k) continue;
            pq.push({*t % a[i], a[i], t});
        }
    }

    llong ans = 0;
    for (int m = 2 * n - 1; m--; ) {
        int cost, src;
        int* ptr;
        tie(cost, src, ptr) = pq.top();
        pq.pop();

        ans += cost;
        int div = *ptr / src;
        ++ptr;
        if (ptr == a + n or *ptr / src != div) continue;
        pq.push({*ptr % src, src, ptr});
    }
    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 232 ms 17936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 4856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 487 ms 67220 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 9064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 286 ms 34464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 291 ms 34444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 4828 KB Output isn't correct
2 Halted 0 ms 0 KB -