Submission #481715

#TimeUsernameProblemLanguageResultExecution timeMemory
481715JohannSirni (COCI17_sirni)C++14
42 / 140
5071 ms1868 KiB
// https://oj.uz/problem/view/COCI17_sirni #include<bits/stdc++.h> using namespace std; #define ll long long #define vi vector<int> #define vb vector<bool> int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vi cards(n); for (int i = 0; i < n; i++) { cin >> cards[i]; } int next = 0, curr = 0; vb visited(n, false); ll total = 0; vi dists(n, INT_MAX); for (int i = 0; i < n-1; i++) { curr = next; next = 0; visited[curr] = true; for (int v = 0; v < n; v++) { if (visited[v]) continue; dists[v] = min(dists[v], min(cards[curr] % cards[v], cards[v] % cards[curr])); if (dists[v] < dists[next]) next = v; } total += (ll) dists[next]; } cout << total << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...