# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
994767 |
2024-06-08T05:06:25 Z |
김은성(#10865) |
봉쇄 시간 (IOI23_closing) |
C++17 |
|
1000 ms |
42308 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;
mx = max((i-X+1) + (Y-j+1) + it->second, 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++){
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
1031 ms |
42308 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 |
15128 KB |
1st lines differ - on the 1st token, expected: '30', found: '19' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14940 KB |
Output is correct |
2 |
Incorrect |
2 ms |
15128 KB |
1st lines differ - on the 1st token, expected: '30', found: '19' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14940 KB |
Output is correct |
2 |
Incorrect |
2 ms |
15128 KB |
1st lines differ - on the 1st token, expected: '30', found: '19' |
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 |
- |