Submission #345152

# Submission time Handle Problem Language Result Execution time Memory
345152 2021-01-07T05:30:15 Z ThinGarfield Sirni (COCI17_sirni) C++11
0 / 140
5000 ms 5700 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define F first
#define S second

constexpr ll big = 1e18 + 18;
constexpr int maxn = 10e5 + 5;
int n;
int p[maxn];
ll dist[maxn];
unordered_set<int> notdone;

ll weight(int a, int b) { return min(p[a] % p[b], p[b] % p[a]); }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        dist[i] = weight(0, i);
        notdone.emplace(i);
    }
    notdone.erase(0);
    ll COST = 0;
    dist[0] = 0;

    while (!notdone.empty()) {
        ll mindist = big;
        int minode = -1;
        for (int node : notdone) {
            if (dist[node] < mindist) {
                mindist = node;
                minode = node;
            }
        }
        notdone.erase(minode);
        COST += dist[minode];
        dist[minode] = 0;
        for (int nbr : notdone) {
            dist[nbr] = min(dist[nbr], weight(minode, nbr));
        }
    }
    cout << COST;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5058 ms 5700 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1399 ms 1140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5062 ms 5648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5046 ms 2424 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5078 ms 5648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5032 ms 5648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2652 ms 1516 KB Output isn't correct
2 Halted 0 ms 0 KB -