using namespace std;
#include "closing.h"
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#define ll long long
#define ld long double
#define INF 1000000000000000000
struct urcity{
vector<pair<int,int>> v;
urcity(){}
};
int sub1(int n,int x,int y,ll k,vector<int> U,vector<int> V, vector<int> W){
vector<urcity> v;
v.clear();
v.resize(n);
for (int i=0;i<n-1;i++){
v[U[i]].v.push_back({V[i],W[i]});
v[V[i]].v.push_back({U[i],W[i]});
}
int z=0;
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
q.push({0,x});
q.push({0,y});
pair<ll,int> p;
set<int> s;
while (!q.empty()&&q.top().first<=k){
p=q.top();
q.pop();
if (s.find(p.second)!=s.end()){continue;}
s.insert(p.second);
k-=p.first;
z++;
for (auto i:v[p.second].v){
q.push({p.first+i.second,i.first});
}
}
return z;
}
struct city{
ll dl,dr;
city(){}
};
int max_score(int n,int l,int r,ll m,vector<int> U,vector<int> V, vector<int> w){
int z=sub1(n,l,r,m,U,V,w);
if (l>r){swap(l,r);}
vector<city> v;
v.resize(n);
v[l].dl=0;
v[r].dr=0;
for (int i=l+1;i<n;i++){v[i].dl=v[i-1].dl+w[i-1];}
for (int i=r+1;i<n;i++){v[i].dr=v[i-1].dr+w[i-1];}
for (int i=l-1;i>=0;i--){v[i].dl=v[i+1].dl+w[i];}
for (int i=r-1;i>=0;i--){v[i].dr=v[i+1].dr+w[i];}
vector<pair<ll,int>> g;
for (int i=0;i<l;i++){g.push_back({v[i].dl,i});}
for (int i=r+1;i<n;i++){g.push_back({v[i].dr,i});}
sort(g.begin(),g.end());
for (int i=0;i<l;i++){
bool f=false;
for (auto j=g.begin();j!=g.end();j++){
if (f&&((v[i].dr-v[i].dl)<(*j).first)){
g.insert(j,{v[i].dr-v[i].dl,-1});
f=false;
break;
}
if ((*j).second==i){f=true;}
}
if (f){g.insert(g.end(),{v[i].dr-v[i].dl,-1});}
}
for (int i=r+1;i<n;i++){
bool f=false;
for (auto j=g.begin();j!=g.end();j++){
if (f&&((v[i].dl-v[i].dr)<(*j).first)){
g.insert(j,{v[i].dl-v[i].dr,-1});
f=false;
break;
}
if ((*j).second==i){f=true;}
}
if (f){g.insert(g.end(),{v[i].dl-v[i].dr,-1});}
}
vector<ll> gg;
gg.resize(g.size()+1);
gg[0]=0;
for (int i=1;i<=(int)g.size();i++){
gg[i]=gg[i-1]+g[i-1].first;
}
for (int i=l;i<=r;i++){
ll x=0;
int k=gg.size()-1;
for (int j=l;j<i;j++){x+=v[j].dl;}
for (int j=i;j<=r;j++){x+=v[j].dr;}
for (int j=i;j<=r;j++){
x-=v[j].dr;
x+=max(v[j].dl,v[j].dr);
while ((k>=0)&&((x+gg[k])>m)){k--;}
if (k==-1){break;}
z=max(z,(r-l+1)+(j-i+1)+k);
}
}
return z;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1078 ms |
23512 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
420 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
360 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
420 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
360 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
352 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
420 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
360 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
352 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
388 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
11 ms |
856 KB |
Output is correct |
27 |
Correct |
8 ms |
604 KB |
Output is correct |
28 |
Correct |
10 ms |
604 KB |
Output is correct |
29 |
Correct |
7 ms |
860 KB |
Output is correct |
30 |
Correct |
7 ms |
752 KB |
Output is correct |
31 |
Correct |
5 ms |
604 KB |
Output is correct |
32 |
Correct |
9 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |