# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
489871 |
2021-11-25T02:15:35 Z |
8e7 |
Sirni (COCI17_sirni) |
C++17 |
|
5000 ms |
5764 KB |
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <assert.h>
#include <cmath>
#include <iomanip>
#include <random>
using namespace std;
void debug(){cout << endl;};
template<class T, class ...U> void debug(T a, U ... b){cout << a << " ", debug(b ...);};
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
};
#define ll long long
#define maxn 100005
#define maxc 10000005
#define mod 1000000007
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
bool rig[maxc], lef[maxc];
int dis[maxn];
bool found[maxn];
priority_queue<pii, vector<pii>, greater<pii> > pq;
vector<int> a;
int n;
void upd(int x) {
for (int i = 0;i < n;i++) {
if (!found[i] && min(x % a[i], a[i] % x) < dis[i]) {
dis[i] = min(x % a[i], a[i]%x);
pq.push({dis[i], i});
}
}
/*
for (int i = x;i < maxc;i += x) {
if (!rig[i]) {
rig[i] = 1;
int ind = lower_bound(a.begin(), a.end(), i) - a.begin();
if (ind < n && !found[ind] && a[ind] - i < dis[ind]) {
dis[ind] = a[ind] - i;
pq.push({dis[ind], ind});
}
}
}
int tmp = x;
for (int i = 1;i * i <= x;i++) {
tmp = x / i;
if (!lef[tmp]) {
lef[tmp] = 1;
int ind = upper_bound(a.begin(), a.end(), tmp) - a.begin()-1;
if (ind >= 0 && !found[ind] && x % a[ind] < dis[ind]) {
dis[ind] = x % a[ind];
pq.push({dis[ind], ind});
}
}
}
for (;tmp >= 1;tmp--) {
if (!lef[tmp]) {
lef[tmp] = 1;
int ind = upper_bound(a.begin(), a.end(), tmp) - a.begin()-1;
if (ind >= 0 && !found[ind] && x % a[ind] < dis[ind]) {
dis[ind] = x % a[ind];
pq.push({dis[ind], ind});
}
}
}
*/
}
int main() {
io
cin >> n;
a.resize(n, 0);
for (int i = 0;i < n;i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
a.resize(int(unique(a.begin(), a.end()) - a.begin()));
n = a.size();
dis[0] = 0;
found[0] = 1;
for (int i = 1;i < n;i++) dis[i] = 1<<30;
upd(a[0]);
int ans = 0;
while (pq.size()) {
pii cur = pq.top();pq.pop();
if (cur.ff != dis[cur.ss] || found[cur.ss]) continue;
ans += cur.ff;
found[cur.ss] = 1;
upd(a[cur.ss]);
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
332 KB |
Output is correct |
2 |
Correct |
5 ms |
332 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
332 KB |
Output is correct |
2 |
Correct |
4 ms |
324 KB |
Output is correct |
3 |
Correct |
6 ms |
352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
332 KB |
Output is correct |
2 |
Correct |
5 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5042 ms |
3224 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
993 ms |
736 KB |
Output is correct |
2 |
Correct |
440 ms |
1832 KB |
Output is correct |
3 |
Execution timed out |
5085 ms |
3784 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5093 ms |
3172 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5086 ms |
1336 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5093 ms |
3300 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5088 ms |
2260 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2021 ms |
1192 KB |
Output is correct |
2 |
Execution timed out |
5058 ms |
5764 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |