# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
994789 |
2024-06-08T05:44:57 Z |
김은성(#10865) |
봉쇄 시간 (IOI23_closing) |
C++17 |
|
1000 ms |
39744 KB |
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<pair<int, ll> > graph[200009];
int inv[200009];
ll psum[200009], distx[200009], disty[200009], predistx[200009], predisty[200009], predistmx[200009];
void dfs(int v, int cur, ll dist){
if(inv[v] != -1)
return;
inv[v] = cur;
psum[cur] = dist;
int i;
for(i=0; i<graph[v].size(); i++){
dfs(graph[v][i].first, cur+1, dist + graph[v][i].second);
}
}
int max_score(int N, int X, int Y, long long K,
std::vector<int> U, std::vector<int> V, std::vector<int> W){
int i, j;
for(i=0; i<N; i++){
graph[i].clear();
inv[i] = -1;
psum[i] = -1;
}
for(i=0; i<N-1; i++){
graph[U[i]].push_back(make_pair(V[i], W[i]));
graph[V[i]].push_back(make_pair(U[i], W[i]));
}
for(i=0; i<N; i++){
if(graph[i].size() == 1){
dfs(i, 0, 0);
break;
}
}
X = inv[X];
Y = inv[Y];
for(i=0; i<N; i++){
distx[i] = abs(psum[X] - psum[i]);
disty[i] = abs(psum[Y] - psum[i]);
predistx[i] = (i==0 ? 0 : predistx[i-1]) + distx[i];
predisty[i] = (i==0 ? 0 : predisty[i-1]) + disty[i];
predistmx[i] = (i==0 ? 0 : predistmx[i-1]) + max(distx[i], disty[i]);
}
if(X > Y)
swap(X, Y);
vector<ll> temp;
vector<pair<ll, int> > ret;
for(i=0; i<X; i++){
temp.push_back(distx[i]);
}
for(i=Y+1; i<N; i++){
temp.push_back(disty[i]);
}
sort(temp.begin(), temp.end());
ret.push_back(make_pair(0, 0));
for(i=0; i<temp.size(); i++){
ret.push_back(make_pair((i==0 ? 0 : ret.back().first) + temp[i], i+1));
}
int mx = 0;
for(i=X; i<=Y; i++){
for(j=X; j<=Y; j++){
ll curdist = 0;
if(i < j){
curdist += predistx[i] - (X==0 ? 0 : predistx[X-1]);
curdist += predisty[Y] - (j==0 ? 0 : predisty[j-1]);
}
else{
curdist += (j==0 ? 0 : predistx[j-1]) - (X==0 ? 0 : predistx[X-1]);
curdist += predistmx[i] - (j==0 ? 0 : predistmx[j-1]);
curdist += predisty[Y] - predisty[i];
}
//printf("i=%d j=%d curdist=%lld\n", i, j, curdist);
if(curdist > K)
continue;
vector<pair<ll, int> >::iterator it = lower_bound(ret.begin(), ret.end(), make_pair(K-curdist+1, 0))-1;
//printf("i=%d j=%d curdist=%lld more=%d\n", i, j, curdist, it->second);
mx = max((i-X+1) + (Y-j+1) + it->second, mx);
}
}
for(i=0; i<=Y; i++){
ll curdist = predisty[Y] - (i==0 ? 0 : predisty[i-1]);
if(curdist > K)
continue;
int now = (Y-i+1);
vector<ll> temp;
for(j=0; j<N; j++){
if(i<=j && j<=Y)
temp.push_back(max(distx[j] - disty[j], 0ll));
else
temp.push_back(distx[j]);
}
for(j=Y+1; j<N; j++){
temp.push_back(disty[j]);
}
//printf("i=%d curdist=%lld\n", i, curdist);
sort(temp.begin(), temp.end());
for(j=0; j<temp.size(); j++){
curdist += temp[j];
//printf("j=%d\n", j);
if(curdist > K)
break;
}
mx = max(now + j,mx);
}
//printf("mx=%d\n", mx);
//printf("done\n");
for(i=X; i<N; i++){
ll curdist = predistx[i] - (X==0 ? 0 : predistx[X-1]);
if(curdist > K)
continue;
int now = (i-X+1);
vector<ll> temp;
for(j=0; j<N; j++){
if(X<=j && j<=i)
temp.push_back(max(disty[j] - distx[j], 0ll));
else
temp.push_back(disty[j]);
}
for(j=Y+1; j<N; j++){
temp.push_back(distx[j]);
}
sort(temp.begin(), temp.end());
for(j=0; j<temp.size(); j++){
curdist += temp[j];
if(curdist > K)
break;
}
mx = max(now + j,mx);
}
//printf("mx=%d\n", mx);
ll curdist = predistmx[Y] - (X==0 ? 0 : predistmx[X-1]);
if(curdist <= K){
ll temp1[6009];
for(i=0; i<=6008; i++)
temp1[i] = 0x3fffffffffffffff;
for(i=0; i<=X; i++){
for(j=0; j<=i; j++){
int now = (X-i+1) + (X-j+1);
temp1[now] = max(temp1[now], predisty[X] - (i==0 ? 0 : predisty[i-1]) +
(i==0 ? 0 : predistx[i-1]) - (j==0 ? 0 : predistx[j-1]));
}
}
for(i=Y; i<N; i++){
for(j=i; j<N; j++){
ll cur = predistx[i] - (Y==0 ? 0 : predistx[Y-1]) +
predisty[j] - predisty[i];
if(cur + curdist <= K){
int ttt = lower_bound(temp1, temp1+6009, K-curdist-cur + 1) - temp1 - 1;
mx = max((i-Y+1) + (j-Y+1) + ttt, mx);
}
}
}
}
//printf("mx=%d\n", mx);
return mx;
}
Compilation message
closing.cpp: In function 'void dfs(int, int, ll)':
closing.cpp:14:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(i=0; i<graph[v].size(); i++){
| ~^~~~~~~~~~~~~~~~
closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:57:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(i=0; i<temp.size(); i++){
| ~^~~~~~~~~~~~
closing.cpp:98:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | for(j=0; j<temp.size(); j++){
| ~^~~~~~~~~~~~
closing.cpp:124:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
124 | for(j=0; j<temp.size(); j++){
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
14936 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1076 ms |
39744 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14940 KB |
Output is correct |
2 |
Incorrect |
2 ms |
14940 KB |
1st lines differ - on the 1st token, expected: '30', found: '29' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14940 KB |
Output is correct |
2 |
Incorrect |
2 ms |
14940 KB |
1st lines differ - on the 1st token, expected: '30', found: '29' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14940 KB |
Output is correct |
2 |
Incorrect |
2 ms |
14940 KB |
1st lines differ - on the 1st token, expected: '30', found: '29' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
14936 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
14936 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
14936 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
14936 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
14936 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |