Submission #990112

# Submission time Handle Problem Language Result Execution time Memory
990112 2024-05-29T16:01:26 Z Ska Sirni (COCI17_sirni) C++14
42 / 140
8 ms 1628 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;

int n;
int a[N];

namespace sub1 {
    int d[N];
    bool used[N];

    void solve() {
        fill(d + 2, d + n + 1, 2e9);
        d[1] = 0;
        long long res = 0;
        for (int i = 1; i <= n; ++i) {
            int k = -1;
            for (int j = 1; j <= n; ++j) {
                if (!used[j] && (k == -1 || d[j] < d[k])) {
                    k = j;
                }
            }
            used[k] = true;
            res += d[k];
            for (int j = 1; j <= n; ++j) {
                d[j] = min(d[j], min(a[k] % a[j], a[j] % a[k]));
            }
        }
        cout << res << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    if (n <= 1000) {
        sub1::solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 348 KB Output is correct
2 Correct 6 ms 604 KB Output is correct
3 Correct 5 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 348 KB Output is correct
2 Correct 6 ms 624 KB Output is correct
3 Correct 6 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 6 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 1368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -