# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1004155 |
2024-06-21T05:56:03 Z |
TahirAliyev |
Sirni (COCI17_sirni) |
C++17 |
|
780 ms |
786432 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define oo 1e9
const int MAX = 1e5 + 5, MX = 1e7 + 7;
int n;
int arr[MAX];
int nxt[MX];
vector<pii> E[MX];
struct DSU{
int par[MAX];
void init(){
for(int i = 0; i < MAX; i++) par[i] = -1;
}
int get(int i){
if(par[i] < 0) return i;
return par[i] = get(par[i]);
}
bool unite(int u, int v){
u = get(u), v = get(v);
if(u == v) return 0;
if(-par[u] < -par[v]) swap(u, v);
par[u] += par[v];
par[v] = u;
return 1;
}
};
DSU dsu;
void solve(){
cin >> n;
dsu.init();
for(int i = 1; i <= n; i++){
cin >> arr[i];
if(nxt[arr[i]]) dsu.unite(i, nxt[arr[i]]);
nxt[arr[i]] = i;
}
int cur = 0;
for(int i = MX - 1; i >= 1; i--){
if(nxt[i]) cur = nxt[i];
nxt[i] = cur;
}
for(int i = 1; i <= n; i++){
if(nxt[arr[i] + 1] && arr[nxt[arr[i] + 1] < 2 * arr[i]]) E[arr[nxt[arr[i] + 1]] - arr[i]].push_back({i, nxt[arr[i] + 1]});
for(int j = 2 * arr[i]; j < MX; j += arr[i]){
if(nxt[j] && arr[nxt[j] < j + arr[i]]) E[arr[nxt[j]] - j].push_back({i, nxt[j]});
}
}
int ans = 0;
for(int i = 0; i < MX; i++){
for(auto a : E[i]){
if(dsu.unite(a.first, a.second)){
ans += i;
}
}
}
cout << ans << '\n';
}
signed main(){
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
int t = 1;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
314412 KB |
Output is correct |
2 |
Correct |
284 ms |
395092 KB |
Output is correct |
3 |
Correct |
153 ms |
314736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
166 ms |
314308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
314448 KB |
Output is correct |
2 |
Correct |
127 ms |
314288 KB |
Output is correct |
3 |
Correct |
132 ms |
314448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
248 ms |
335192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
156 ms |
318176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
363 ms |
364016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
250 ms |
321392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
218 ms |
340568 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
218 ms |
348992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
319060 KB |
Output is correct |
2 |
Runtime error |
780 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |