답안 #900073

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
900073 2024-01-07T14:46:34 Z bleahbleah 봉쇄 시간 (IOI23_closing) C++17
0 / 100
48 ms 13576 KB
#include <bits/stdc++.h>
#include "closing.h"
#define all(x) (x).begin(),(x).end()
using namespace std;

using ll = long long;
using ld = long double;

//#define int ll
#define sz(x) ((int)(x).size())

using pii = pair<ll,ll>;
using tii = tuple<int,int,int>;

const int nmax = 2e3 + 5;

vector<pii> g[nmax];

vector<ll> dX, dY;
vector<int> occX;

vector<int> chain;

void dfs(int node, int f, vector<ll>& d, ll accum) {
  d[node] = accum;
  for(auto [x, c] : g[node])
    if(x != f)
      dfs(x, node, d, accum + c);
  
  return;
}

void findchain(int node, int f, int Y) {
  if(sz(chain) && chain.back() == Y) return;
  chain.emplace_back(node);
  for(auto [x, e] : g[node]) {
    if(x == f) continue;
    findchain(x, node, Y);
  }
  if(chain.back() == Y) return;
  chain.pop_back();
}

int disjointed(int n, ll K, int X, int Y) {
  priority_queue<pii, vector<pii>, greater<pii>> heap;
  
  vector<int> occY(n, 0);
  
  heap.emplace(0, Y);
  
  int scorefromY = 0;
  
  while(!heap.empty()) {
    auto [C, node] = heap.top();
    K -= C;
    
    if(K < 0) break;
    
    heap.pop();
    occY[node] = 1;
    scorefromY++;
    
    for(auto [x, e] : g[node]) {
      if(occX[x] || occY[x]) continue;
      heap.emplace(C + e, x);
    }
  }
  
  return scorefromY;
} 

int tied(int n, ll K, int X, int Y) {
  int scorefromY = 0;
  priority_queue<pii, vector<pii>, greater<pii>> heap;
  
  vector<ll> costs(n);
  vector<int> occY(n, 0);
  
  for(int i = 0; i < n; i++)
    costs[i] = occX[i]? max(0LL, dY[i] - dX[i]) : dY[i];
  
  
  for(auto x : chain) {
    occY[x] = 1;
    if(occX[x] == 1) break;
  }
  
  for(auto x : chain) {
    if(!occY[x]) continue;
    scorefromY++;
    K -= costs[x];
  
    for(auto [nv, e] : g[x]) {
      if(occY[nv]) continue;
      heap.emplace(costs[nv], nv);
    }
  }
  
  if(K < 0) return 1;
  
  while(!heap.empty()) {
    auto [C, node] = heap.top();
    K -= C;
    
    if(K < 0) break;
    
    heap.pop();
    occY[node] = 1;
    scorefromY++;
    
    for(auto [x, e] : g[node]) {
      if(occX[x] || occY[x]) continue;
      heap.emplace(costs[x], x);
    }
  }
  
  return scorefromY;
}

int max_score(int n, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W) {
  
  for(int i = 0; i < n; i++) g[i].clear();
  chain.clear();
  dX.clear();
  dY.clear();
  occX.clear();
  
  for(int i = 0; i < n - 1; i++)
    g[U[i]].emplace_back(V[i], W[i]),
    g[V[i]].emplace_back(U[i], W[i]);
    
  dX.resize(n);
  dY.resize(n);
  
  dfs(X, X, dX, 0);
  dfs(Y, Y, dY, 0);
  
  findchain(X, X, Y);
  
  reverse(all(chain));
  
  priority_queue<pii, vector<pii>, greater<pii>> heap;
  heap.emplace(0, X);
  
  occX.resize(n);
  
  int scorefromX = 0;
  
  int maxscore = 2;
  
  
  while(!heap.empty()) {
    auto [C, node] = heap.top();
    K -= C;
    
    //cerr << node << '\n';
    
    if(K < 0) break;
    
    heap.pop();
    scorefromX++;
    occX[node] = 1;
    
    for(auto [x, e] : g[node]) {
      if(!occX[x])
        heap.emplace(C + e, x);
    }
    
    maxscore = max(maxscore, scorefromX + max(disjointed(n, K, X, Y), tied(n, K, X, Y)));
  }
  
  return maxscore;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 48 ms 13576 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '30', found: '19'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '30', found: '19'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '30', found: '19'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '30', found: '19'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '30', found: '19'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '30', found: '19'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '30', found: '19'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '30', found: '19'
4 Halted 0 ms 0 KB -