# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1109932 |
2024-11-08T07:15:44 Z |
KasymK |
Nile (IOI24_nile) |
C++17 |
|
38 ms |
6088 KB |
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 1e5+5;
int rep[N], sz[N], n, answer;
void init(){
for(int i = 0; i < n; ++i)
rep[i] = i, sz[i] = 1;
answer = 2*n;
}
int find(int x){
if(rep[x]==x)
return x;
return rep[x]=find(rep[x]);
}
void merge(int a, int b){
a = find(a), b = find(b);
if(sz[a]<sz[b])
swap(a, b);
if(sz[a]&1 and sz[b]&1)
answer -= 2;
sz[a] += sz[b];
rep[b] = a;
}
vector<ll> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E){
n = (int)W.size();
vector<pii> v;
for(int i = 0; i < n; ++i)
v.pb({W[i], i});
sort(all(v));
vector<array<int, 3>> as;
for(int i = 1; i < n; ++i)
as.pb({v[i].ff-v[i-1].ff, v[i].ss, v[i-1].ss});
sort(all(as));
init();
vector<pii> Q;
for(int i = 0; i < (int)E.size(); ++i)
Q.pb({E[i], i});
vector<ll> ans((int)Q.size());
int ii = 0;
for(auto &d : Q){
while(ii<(int)as.size() and as[ii][0]<=d.ff)
merge(as[ii][1], as[ii][2]), ii++;
ans[d.ss] = answer;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
6088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
6072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
6072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |