# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1103482 |
2024-10-21T04:04:13 Z |
ezzzay |
Nile (IOI24_nile) |
C++17 |
|
76 ms |
15360 KB |
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define ll long long
const int N=3e5+5;
int par[N];
int sbtr[N];
int H;
void init(int n){
H=2*n;
for(int i=0;i<n;i++){
par[i]=i;
sbtr[i]=1;
}
}
int find(int x){
if(par[x]==x)return x;
return par[x]=find(par[x]);
}
void unite(int x, int y){
int px=find(x),py=find(y);
if(px==py)return;
if(sbtr[py]>sbtr[px])swap(px,py);
int a=sbtr[px],b=sbtr[py];
sbtr[px]+=sbtr[py];
par[py]=px;
if(a%2 and b%2 )H-=2;
}
std::vector<long long> calculate_costs(std::vector<int> W, std::vector<int> A,
std::vector<int> B, std::vector<int> E) {
init(int(W.size()));
int q = (int)E.size();
int n = W.size();
if(q<=5){
vector<ll>ans;
vector<pair<ll,ll> >v;
for(int i=0;i<n;i++){
v.pb({W[i],i});
}
sort(v.begin(),v.end());
for(int f=0;f<q;f++){
ll d=E[f];
vector<vector<ll> > dp ( n+5 , vector<ll> (2));
for(int i=1;i<=n;i++){
dp[i][0]=1e17;
dp[i][1]=1e17;
}
for(int i=0;i<n;i++){
int a,b,c;
a=v[i].ss;
if(i>0)b=v[i-1].ss;
if(i>1)c=v[i-2].ss;
if(i>0) {
if(abs(W[a]-W[b])<=d) dp[i+1][1]=min(dp[i+1][1],dp[i][0]-A[b]+B[b]+B[a]);
}
if(i>1) {
if(abs(W[a]-W[c])<=d) dp[i+1][1]=min(dp[i+1][1],dp[i-1][0]-A[c]+B[c]+B[a]+A[b]);
}
dp[i+1][0]=min(dp[i+1][0],min(dp[i][1],dp[i][0])+A[a]);
}
ans.pb(min(dp[n][0],dp[n][1]));
}
return ans;
}
vector<ll>ans(q);
vector<pair<ll,ll> >v;
vector<pair<ll, pair<int,int> > >vc;
for(int i=0;i<n;i++){
v.pb({W[i],i});
}
sort(v.begin(),v.end());
for(int i=1;i<n;i++){
int x=abs(v[i].ff-v[i-1].ff);
int a=v[i-1].ss,b=v[i].ss;
vc.pb({x,{a,b}});
}
sort(vc.begin(),vc.end());
int idx=0;
vector<pair<int,int>>vec;
for(int i=0;i<q;i++){
vec.pb({E[i],i});
}
sort(vec.begin(),vec.end());
for(int f=0;f<q;f++){
ll d=vec[f].ff;
int k=vec[f].ss;
while(vc[idx].ff<=d and idx<vc.size()){
int a=vc[idx].ss.ff,b=vc[idx].ss.ss;
unite(a,b);
idx++;
}
ans[k]=H;
}
return ans;
}
Compilation message
nile.cpp: In function 'std::vector<long long int> calculate_costs(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
nile.cpp:92:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | while(vc[idx].ff<=d and idx<vc.size()){
| ~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2684 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
12548 KB |
Output is correct |
2 |
Correct |
49 ms |
15052 KB |
Output is correct |
3 |
Correct |
58 ms |
15040 KB |
Output is correct |
4 |
Correct |
48 ms |
14780 KB |
Output is correct |
5 |
Correct |
51 ms |
15052 KB |
Output is correct |
6 |
Correct |
62 ms |
15032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
12480 KB |
Output is correct |
2 |
Correct |
58 ms |
12544 KB |
Output is correct |
3 |
Correct |
56 ms |
12528 KB |
Output is correct |
4 |
Correct |
56 ms |
12540 KB |
Output is correct |
5 |
Correct |
56 ms |
12548 KB |
Output is correct |
6 |
Correct |
53 ms |
12524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2684 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2804 KB |
Output is correct |
8 |
Correct |
3 ms |
2504 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
2 ms |
2576 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2684 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
48 ms |
12548 KB |
Output is correct |
8 |
Correct |
49 ms |
15052 KB |
Output is correct |
9 |
Correct |
58 ms |
15040 KB |
Output is correct |
10 |
Correct |
48 ms |
14780 KB |
Output is correct |
11 |
Correct |
51 ms |
15052 KB |
Output is correct |
12 |
Correct |
62 ms |
15032 KB |
Output is correct |
13 |
Correct |
55 ms |
12480 KB |
Output is correct |
14 |
Correct |
58 ms |
12544 KB |
Output is correct |
15 |
Correct |
56 ms |
12528 KB |
Output is correct |
16 |
Correct |
56 ms |
12540 KB |
Output is correct |
17 |
Correct |
56 ms |
12548 KB |
Output is correct |
18 |
Correct |
53 ms |
12524 KB |
Output is correct |
19 |
Correct |
2 ms |
2804 KB |
Output is correct |
20 |
Correct |
3 ms |
2504 KB |
Output is correct |
21 |
Correct |
2 ms |
2640 KB |
Output is correct |
22 |
Correct |
2 ms |
2576 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2640 KB |
Output is correct |
25 |
Correct |
62 ms |
15100 KB |
Output is correct |
26 |
Correct |
59 ms |
15360 KB |
Output is correct |
27 |
Correct |
63 ms |
15352 KB |
Output is correct |
28 |
Correct |
62 ms |
12676 KB |
Output is correct |
29 |
Correct |
76 ms |
15184 KB |
Output is correct |
30 |
Correct |
69 ms |
15104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
12480 KB |
Output is correct |
2 |
Correct |
58 ms |
12544 KB |
Output is correct |
3 |
Correct |
56 ms |
12528 KB |
Output is correct |
4 |
Correct |
56 ms |
12540 KB |
Output is correct |
5 |
Correct |
56 ms |
12548 KB |
Output is correct |
6 |
Correct |
53 ms |
12524 KB |
Output is correct |
7 |
Correct |
54 ms |
12728 KB |
Output is correct |
8 |
Correct |
60 ms |
12760 KB |
Output is correct |
9 |
Correct |
66 ms |
12728 KB |
Output is correct |
10 |
Correct |
58 ms |
12736 KB |
Output is correct |
11 |
Correct |
69 ms |
12728 KB |
Output is correct |
12 |
Correct |
63 ms |
12736 KB |
Output is correct |
13 |
Correct |
72 ms |
12728 KB |
Output is correct |
14 |
Correct |
60 ms |
12736 KB |
Output is correct |
15 |
Correct |
62 ms |
12736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2684 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
48 ms |
12548 KB |
Output is correct |
9 |
Correct |
49 ms |
15052 KB |
Output is correct |
10 |
Correct |
58 ms |
15040 KB |
Output is correct |
11 |
Correct |
48 ms |
14780 KB |
Output is correct |
12 |
Correct |
51 ms |
15052 KB |
Output is correct |
13 |
Correct |
62 ms |
15032 KB |
Output is correct |
14 |
Correct |
55 ms |
12480 KB |
Output is correct |
15 |
Correct |
58 ms |
12544 KB |
Output is correct |
16 |
Correct |
56 ms |
12528 KB |
Output is correct |
17 |
Correct |
56 ms |
12540 KB |
Output is correct |
18 |
Correct |
56 ms |
12548 KB |
Output is correct |
19 |
Correct |
53 ms |
12524 KB |
Output is correct |
20 |
Correct |
2 ms |
2804 KB |
Output is correct |
21 |
Correct |
3 ms |
2504 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2576 KB |
Output is correct |
24 |
Correct |
2 ms |
2640 KB |
Output is correct |
25 |
Correct |
2 ms |
2640 KB |
Output is correct |
26 |
Correct |
62 ms |
15100 KB |
Output is correct |
27 |
Correct |
59 ms |
15360 KB |
Output is correct |
28 |
Correct |
63 ms |
15352 KB |
Output is correct |
29 |
Correct |
62 ms |
12676 KB |
Output is correct |
30 |
Correct |
76 ms |
15184 KB |
Output is correct |
31 |
Correct |
69 ms |
15104 KB |
Output is correct |
32 |
Correct |
54 ms |
12728 KB |
Output is correct |
33 |
Correct |
60 ms |
12760 KB |
Output is correct |
34 |
Correct |
66 ms |
12728 KB |
Output is correct |
35 |
Correct |
58 ms |
12736 KB |
Output is correct |
36 |
Correct |
69 ms |
12728 KB |
Output is correct |
37 |
Correct |
63 ms |
12736 KB |
Output is correct |
38 |
Correct |
72 ms |
12728 KB |
Output is correct |
39 |
Correct |
60 ms |
12736 KB |
Output is correct |
40 |
Correct |
62 ms |
12736 KB |
Output is correct |
41 |
Incorrect |
64 ms |
12728 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |