답안 #900075

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
900075 2024-01-07T14:56:09 Z bleahbleah 봉쇄 시간 (IOI23_closing) C++17
9 / 100
46 ms 10008 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();
    //cerr << C << ' ';
    K -= C;
    
    if(K < 0) break;
    
    heap.pop();
    occY[node] = 1;
    scorefromY++;
    
    for(auto [x, e] : g[node]) {
      if(occY[x]) continue;
      heap.emplace(costs[x], x);
    }
  }
  
  //cerr << '\n';
  
  return scorefromY;
}

#undef int
int max_score(int n, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W) {
#define int ll
  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;
}
#undef int
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 46 ms 10008 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Incorrect 1 ms 348 KB 2nd lines differ - on the 1st token, expected: '25', found: '24'
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Incorrect 1 ms 348 KB 2nd lines differ - on the 1st token, expected: '25', found: '24'
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Incorrect 1 ms 348 KB 2nd lines differ - on the 1st token, expected: '25', found: '24'
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Incorrect 1 ms 348 KB 2nd lines differ - on the 1st token, expected: '25', found: '24'
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Incorrect 1 ms 348 KB 2nd lines differ - on the 1st token, expected: '25', found: '24'
20 Halted 0 ms 0 KB -