# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1057683 |
2024-08-14T03:15:48 Z |
vjudge1 |
Sirni (COCI17_sirni) |
C++17 |
|
669 ms |
662256 KB |
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, b, a) for(int i = (b), _a = (a); i >= _a; --i)
#define REP(i, a, b) for(int i = (a), _b = (b); i < _b; ++i)
#define REPD(i, b, a) for(int i = (b), _a = (a); i > _a; --i)
#define MASK(i) (1LL << (i))
#define BIT(mask, i) (((mask) >> (i)) & 1)
#define __builtin_popcount __builtin_popcountll
#define all(val) val.begin(), val.end()
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(v) (int)v.size()
#define fi first
#define se second
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll Rand(ll l, ll r) {return l + rng() % (r - l + 1);}
template<class X, class Y>
bool minimize(X &x, const Y &y) {
if (x > y) {
x = y;
return true;
} else return false;
}
template<class X, class Y>
bool maximize(X &x, const Y &y) {
if (x < y) {
x = y;
return true;
} else return false;
}
template<class T>
T Abs(const T &x) {
return (x < 0 ? -x : x);
}
const int mod = 1e9 + 7;
const int inf = 1e9;
const int N = 1e5 + 5;
const int MAX = 1e7 + 5;
int n, a[N], nxt[MAX];
bool exist[MAX];
int par[MAX], sz[MAX];
vector<pii> g[MAX];
int mx;
int find(int u) {
if(u == par[u]) return u;
return par[u] = find(par[u]);
}
bool join(int u, int v) {
u = find(u); v = find(v);
if(u == v) return false;
if(sz[u] < sz[v]) swap(u, v);
sz[u] += sz[v];
par[v] = u;
return true;
}
void process() {
cin >> n;
FOR(i, 1, n) {
cin >> a[i];
nxt[a[i]] = a[i];
mx = max(mx, a[i]);
exist[a[i]] = 1;
}
FORD(i, mx, 0) {
if(!exist[i]) nxt[i] = nxt[i + 1];
}
sort(a + 1, a + n + 1);
FOR(i, 1, n) {
if(!exist[a[i]]) continue;
for(int j = a[i]; j <= mx; j += a[i]) {
int res = (a[i] == j) ? a[i] + 1 : j;
if(a[i] + j > nxt[res]) g[nxt[res] % a[i]].push_back({nxt[res], a[i]});
}
exist[a[i]] = 0;
}
int ans = 0;
FOR(i, 1, mx) par[i] = i, sz[i] = 1;
FOR(i, 0, mx) {
for(auto [u, v] : g[i]) {
if(join(u, v)) ans += i;
}
}
cout << ans << '\n';
}
signed main() {
if(fopen("test.inp","r")) {
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
}
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// clock_t start = clock();
int ntests = 1;
// cin >> ntests;
while(ntests--) process();
// cerr << "Time elapsed: " << clock() - start << " ms!\n";
return 0;
}
Compilation message
sirni.cpp: In function 'int main()':
sirni.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | freopen("test.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
sirni.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
99 | freopen("test.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
362600 KB |
Output is correct |
2 |
Correct |
79 ms |
364628 KB |
Output is correct |
3 |
Correct |
70 ms |
362576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
242736 KB |
Output is correct |
2 |
Correct |
154 ms |
363088 KB |
Output is correct |
3 |
Correct |
63 ms |
362580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
362576 KB |
Output is correct |
2 |
Correct |
61 ms |
362324 KB |
Output is correct |
3 |
Correct |
62 ms |
362580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
264440 KB |
Output is correct |
2 |
Correct |
97 ms |
294904 KB |
Output is correct |
3 |
Correct |
68 ms |
269892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
256604 KB |
Output is correct |
2 |
Correct |
70 ms |
277104 KB |
Output is correct |
3 |
Correct |
57 ms |
258832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
276028 KB |
Output is correct |
2 |
Correct |
111 ms |
304592 KB |
Output is correct |
3 |
Correct |
65 ms |
268216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
246064 KB |
Output is correct |
2 |
Correct |
105 ms |
302364 KB |
Output is correct |
3 |
Correct |
65 ms |
267844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
374612 KB |
Output is correct |
2 |
Correct |
461 ms |
580936 KB |
Output is correct |
3 |
Correct |
109 ms |
377148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
374568 KB |
Output is correct |
2 |
Correct |
669 ms |
662256 KB |
Output is correct |
3 |
Correct |
120 ms |
380908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
364536 KB |
Output is correct |
2 |
Correct |
656 ms |
657456 KB |
Output is correct |
3 |
Correct |
68 ms |
269892 KB |
Output is correct |