# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
406846 |
2021-05-18T06:08:51 Z |
Falcon |
Sirni (COCI17_sirni) |
C++17 |
|
356 ms |
248420 KB |
#include <bits/stdc++.h>
#ifdef DEBUG
#include "debug.hpp"
#endif
using namespace std;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define rep(i, N) for(int i = 0; i < (N); ++i)
#define rrep(i, N) for(int i = (N) - 1; i >= 0; --i)
#define rep1(i, N) for(int i = 1; i <= (N); ++i)
#define rep2(i, s, e) for(int i = (s); i <= (e); ++i)
#ifdef DEBUG
#define debug(x...) { \
++dbg::depth; \
string dbg_vals = dbg::to_string(x); \
--dbg::depth; \
dbg::fprint(__func__, __LINE__, #x, dbg_vals); \
}
#define light_debug(x) { \
dbg::light = true; \
dbg::dout << __func__ << ":" << __LINE__; \
dbg::dout << " " << #x << " = " << x << endl; \
dbg::light = false; \
}
#else
#define debug(x...) 42
#define light_debug(x) 42
#endif
using ll = long long;
template<typename T>
inline T& ckmin(T& a, T b) { return a = a > b ? b : a; }
template<typename T>
inline T& ckmax(T& a, T b) { return a = a < b ? b : a; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vector<int> p(n); rep(i, n) cin >> p[i];
sort(all(p)); p.erase(unique(all(p)), p.end());
int m{p.back()};
vector<vector<pair<int, int>>> edges(m + 1);
rep(i, n) {
for(int x{p[i]}; x <= m; x += p[i]) {
int j = lower_bound(all(p), x) - p.begin();
if(p[j] < x + p[i])
edges[p[j] - x].push_back({i, j});
}
}
debug(edges);
vector<int> pre(n); iota(all(pre), 0);
auto root = [&](int i) {
int j;
for(j = i; pre[j] != j; j = pre[j]);
for(int t{i}; i != j; i = pre[i], pre[t] = j, t = i);
return j;
};
long long ans{};
auto merge = [&](int i, int j, int c) {
debug(i, j);
i = root(i), j = root(j);
if(i == j) return false;
pre[i] = j;
ans += c;
debug(ans);
return true;
};
int c{};
rep(i, m + 1) {
if(c == n - 1) break;
for(auto [u, v] : edges[i]) {
if(c == n - 1) break;
c += merge(u, v, i);
}
}
cout << ans << '\n';
#ifdef DEBUG
dbg::dout << "\nExecution time: "
<< clock() * 1000 / CLOCKS_PER_SEC
<< "ms" << endl;
#endif
return 0;
}
Compilation message
sirni.cpp: In function 'int main()':
sirni.cpp:33:29: warning: statement has no effect [-Wunused-value]
33 | #define debug(x...) 42
| ^~
sirni.cpp:64:5: note: in expansion of macro 'debug'
64 | debug(edges);
| ^~~~~
sirni.cpp: In lambda function:
sirni.cpp:33:29: warning: statement has no effect [-Wunused-value]
33 | #define debug(x...) 42
| ^~
sirni.cpp:78:9: note: in expansion of macro 'debug'
78 | debug(i, j);
| ^~~~~
sirni.cpp:33:29: warning: statement has no effect [-Wunused-value]
33 | #define debug(x...) 42
| ^~
sirni.cpp:83:9: note: in expansion of macro 'debug'
83 | debug(ans);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
155 ms |
235008 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
146 ms |
235136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
167 ms |
34268 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
37 ms |
25660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
345 ms |
47284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
54 ms |
8744 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
325 ms |
248420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
356 ms |
248136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
187 ms |
237596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |