# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
547286 |
2022-04-10T09:07:35 Z |
AA_Surely |
Sirni (COCI17_sirni) |
C++17 |
|
1027 ms |
786432 KB |
#include <bits/stdc++.h>
#define FOR(i,x,n) for(int i=x; i<n; i++)
#define F0R(i,n) FOR(i,0,n)
#define ROF(i,x,n) for(int i=n-1; i>=x; i--)
#define R0F(i,n) ROF(i,0,n)
#define WTF cout << "WTF" << endl
#define IOS ios::sync_with_stdio(false); cin.tie(0)
#define F first
#define S second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
const int N = 1e5 + 7;
const int A = 1e7 + 7;
const int ALPHA = 27;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int LOG = 22;
struct Edge {
int u, v, w;
inline bool operator < (const Edge other) {
return w < other.w;
}
} x;
int n, era[A];
int par[N];
vector<Edge> eset;
int grand(int x) {
if (par[x] < 0) return x;
return par[x] = grand(par[x]);
}
inline bool merge(int a, int b) {
a = grand(a); b = grand(b);
if (a == b) return 0;
if (par[a] > par[b]) swap(a, b);
par[a] += par[b];
par[b] = a;
return 1;
}
int main() {
IOS;
fill(era, era + A, -1);
cin >> n;
VI ns(n);
F0R(i, n) cin >> ns[i];
sort(ALL(ns));
ns.resize(unique(ALL(ns)) - ns.begin());
n = ns.size();
F0R(i, n) era[ ns[i] ] = i;
R0F(i, A - 1) if (era[i] == -1)
era[i] = era[i + 1];
F0R(i, n) for(int j = ns[i]; j < A; j += ns[i]) if (era[j] != -1) {
x.u = i; x.v = era[j];
x.w = ns[ era[j] ] - j;
eset.pb(x);
if (era[j + 1] != -1 && era[j + 1] != era[j]) {
x.u = i; x.v = era[j + 1];
x.w = ns[ era[j + 1] ] - j;
eset.pb(x);
}
}
sort(ALL(eset));
fill(par, par + n, -1);
LL ans = 0;
F0R(i, eset.size()) if (merge(eset[i].u, eset[i].v)) ans += eset[i].w;
cout << ans << endl;
}
Compilation message
sirni.cpp: In function 'int main()':
sirni.cpp:3:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define FOR(i,x,n) for(int i=x; i<n; i++)
| ^
sirni.cpp:4:19: note: in expansion of macro 'FOR'
4 | #define F0R(i,n) FOR(i,0,n)
| ^~~
sirni.cpp:97:5: note: in expansion of macro 'F0R'
97 | F0R(i, eset.size()) if (merge(eset[i].u, eset[i].v)) ans += eset[i].w;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
39612 KB |
Output is correct |
2 |
Correct |
317 ms |
88820 KB |
Output is correct |
3 |
Correct |
41 ms |
39904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
39692 KB |
Output is correct |
2 |
Runtime error |
766 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
39592 KB |
Output is correct |
2 |
Correct |
39 ms |
39464 KB |
Output is correct |
3 |
Correct |
41 ms |
39716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
64524 KB |
Output is correct |
2 |
Correct |
668 ms |
138392 KB |
Output is correct |
3 |
Correct |
317 ms |
89224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
42688 KB |
Output is correct |
2 |
Correct |
446 ms |
89204 KB |
Output is correct |
3 |
Correct |
293 ms |
64580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
406 ms |
89140 KB |
Output is correct |
2 |
Correct |
867 ms |
138448 KB |
Output is correct |
3 |
Correct |
293 ms |
89196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
199 ms |
45864 KB |
Output is correct |
2 |
Correct |
923 ms |
138380 KB |
Output is correct |
3 |
Correct |
340 ms |
89224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
172 ms |
64520 KB |
Output is correct |
2 |
Runtime error |
842 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
207 ms |
64624 KB |
Output is correct |
2 |
Runtime error |
833 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
42720 KB |
Output is correct |
2 |
Runtime error |
1027 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |